Code Elegance: Java Strings : <p>A program that takes the first two characters of a string and adds them to the front and back of the string. Which version is better?</p>

<pre><code>public String front22(String str) {
  if(str.length()&gt;2) return str.substring(0,2)+str+str.substring(0,2);
  return str+str+str;
}
</code></pre>

<p>or</p>

<pre><code>public String front22(String str) {
  // First figure the number of chars to take
  int take = 2;
  if (take &gt; str.length()) {
     take = str.length();
 }

  String front = str.substring(0, take);
  return front + str + front;
}
</code></pre>

<p>The former strikes me as more elegant. The latter is easier to understand. Any other suggestions for improvement of either is more than welcome!</p>
