Sunday, January 26, 2014

How to remove the last character from a string?

Source:
public class RemoveLastChar {
   public static void main(String[] args) {

      String str = "This is a string.Z";
      System.out.println(str);

      str = str.substring(0, str.length()-1);
      System.out.println(str);
   }
}

Output:
   $ java RemoveLastChar 
   This is a string.Z
   This is a string.

Blog Archive