string.trim()
Java String
String.trim() Removing space from left and right of a string.
Here are some examples with output.
Replacing extra space from beginning and end of the string.
String str = " plus2net ";
System.out.println(str.trim()); //plus2net
We will check the length of the string before and after applying trim()
String str = " plus2net ";
System.out.println(str.length()); // 10
String str_short=str.trim();
System.out.println(str.trim()); //plus2net
System.out.println(str_short.length()); //8
After using trim() the length has decreased from 10 to 8.
« All String functions
« Java
This article is written by plus2net.com team.
Be the first to post comment:
plus2net.com