Advertisement
public String trim()
// Program to trim the leading and trailing blank spaces from a String.
class StringTrim
{
public static void main(String[] ar)
{
String str1= new String(" hello ");
System.out.println("String value is : " + str1);
System.out.println("The trimmed String value is : " + str1.trim());
}
}
String value is : hello
The trimmed String value is : hello
// Example of trim() method
class StringUpper
{
public static void main(String[] ar)
{
String str1= new String(" how is your day going on? ");
System.out.println("String value is : " + str1);
System.out.println("The trimmed String value is : " + str1.trim());
System.out.println("String value : " + str);
}
}
String value is : how is your day going on?
The trimmed String value is : how is your day going on?
String value is : how is your day going on?
Advertisement
// Example of trim() method
class StringUpper2
{
public static void main(String[] ar)
{
String str= new String(" mother nature should be protected ");
System.out.println("String value is : " + str);
str = str.trim(); //result of calling trim() is stored back in String object
System.out.println("String's trimmed value : " + str);
}
}
String value is : mother nature should be protected
String's trimmed value : mother nature should be protected
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement