1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
/* Java String Trim Example. This Java String trim example shows how to remove leading and trailing space from string using trim method of Java String class. */ public class RemoveLeadingTrailingSpace { public static void main(String[] args) { String str = " String Trim Example "; /* * To remove leading and trailing space from string use, * public String trim() method of Java String class. */ String strTrimmed = str.trim(); System.out.println("Original String is: " + str); System.out.println("Removed Leading and trailing space"); System.out.println("New String is: " + strTrimmed); } } /* Output would be Original String is: String Trim Example Removed Leading and trailing space New String is: String Trim Example */ |
Add Comment