/** * @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.com
output:
welcom to java world.! welcom to java world.