title: Swapping the first and the last letter of a string in Java?
body: <pre><code>int length = s.length();
  
  if (length &lt;= 1){
      return s;
  }
  
  else {
  
      return s.charAt(length) + s.substring(1, length-1) + s.charAt(0);
  
  }
  </code></pre>
  
  <p>I'm just trying to swap the first letter and the last letter of a string.</p>
  
  <p>eg. apple -> eppla</p>
  
  <p>It compiled fine and works fine with an empty string or a string with one character only. 
  But  with strings with several characters, it says:</p>
  
  <pre><code>StringIndexOutOfBoundsException occured - see console for stack trace
  </code></pre>
  
  <p>Does tht mean there's something wrong with my code???</p>