/**
* @author lautturi.com
* Java example: remove the last character from string in java
*/
import java.util.*;
public class Lautturi {
public static String removeLastChar(String s) {
return (s == null || s.length() == 0)
? null
: (s.substring(0, s.length() - 1));
}
public static void main(String[] args) {
String str = "welcom to java world.!";
System.out.println(str);
str = removeLastChar(str);
System.out.println(str);
}
}Sourceww:w.lautturi.comoutput:
welcom to java world.! welcom to java world.