String’s trim method does not remove middle spaces.
String trim example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
package org.arpit.java2blog; public class StringTrimExample { public static void main(String[] args) { String str = " Hello world from "; //without trim() System.out.println("Without trim"); System.out.println("----------------------"); System.out.println(str+"java2blog.com"); System.out.println("----------------------"); // with trim() System.out.println("nWith trim"); System.out.println("----------------------"); System.out.println(str.trim()+"java2blog.com"); } } |
1 2 3 4 5 6 7 8 9 10 |
Without trim ---------------------- Hello world from java2blog.com ---------------------- With trim ---------------------- Hello world fromjava2blog.com |