Java-Trimming

Trimming To remove whitespace from the beginning and end of a string (but not the interior) you can use the trim( ) method. Program Program Source public class Javaapp { public static void main(String[] args){ String str1 = new String(” haj sof “); System.out.println(str1); System.out.println(“str1.length = “+str1.length()); str1 = str1.trim(); System.out.println(str1); System.out.println(“str1.length = “+str1.length()); } … Read more…