title: How to remove the last character from a string?
body: <p>I want to remove the last character from a string. I've tried doing this:</p>
  
  <pre><code>public String method(String str) {
      if (str.charAt(str.length()-1)=='x'){
          str = str.replace(str.substring(str.length()-1), "");
          return str;
      } else{
          return str;
      }
  }
  </code></pre>
  
  <p>Getting the length of the string - 1 and replacing the last letter with nothing (deleting it), but every time I run the program, it deletes middle letters that are the same as the last letter.</p>
  
  <p>For example, the word is "admirer"; after I run the method, I get "admie." I want it to return the word admire.</p>