How to remove the last character of a string in Java?

To remove the last character of a string in Java, call String.substring(0, String.length() - 1).
String string = "a string";

String withoutLastCharacter = string.substring(0, string.length() - 1);

System.out.println(withoutLastCharacter); // a strin