Java String trim Example
String class trim method example
String class trim method example. This example shows you how to use trim method.This method Returns a copy of the string, with leading and trailing whitespace omitted.
Here is the code:-
/**
* @(#) Trimstring.java
*Program that Removes white space from both ends of this string.
* @Version 01-May-2008
* @author Rose India Team
*/
public class Trimstring
{
public static void main(String[] args)
{
String str = " Welcome to RoseIndia";
//Removes white space from both ends of this string.vvvvvvv
String s1 = str.trim();
// Display the two strings
System.out.println("old = " + str);
System.out.println("NewString = " + s1);
}
}
|
null
|