Remove leading and trailing space from String in Java
Description
The following code shows how to remove leading and trailing space from String.
Example
/*w ww.j a va 2 s . co m*/
public class Main {
public static void main(String[] args) {
String str = " this is a test from java2s.com ";
String strTrimmed = str.trim();
System.out.println(">" + str+"<");
System.out.println(">" + strTrimmed+"<");
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »