Home Java Beginners Trim String Example



Trim String Example
Posted on: June 8, 2007 at 12:00 AM
In this section, you will learn how to remove the blank spaces.

Trim String Example

     

In this section, you will learn how to remove the blank spaces. For removing  the blank spaces use trim() method that removes the blank spaces and shows only string. 

Description of code:

trim():
This method removes the blank spaces from both ends of the given string (Front and End). 

Here is the code of program:

 

 

 

import java.lang.*;

public class StringTrim{
  public static void main(String[] args) {
  System.out.println("String trim example!");
  String str = " RoseIndia";
  System.out.println("Given String :" + str);
  System.out.println("After trim :" +str.trim());
  }
}

Download this example.

Output of program:

C:\vinod\Math_package>javac StringTrim.java

C:\vinod\Math_package>java StringTrim
String trim example!
Given String :  RoseIndia
After trim :RoseIndia

Related Tags for Trim String Example:
cstringmethodremovevithismoveshowforspacestrimblanklanwsshbotespaceuseimfromceinmnttraceesemfrontendmehowsspatpacmovingkishaivandstrremovingvinssriringthshosthatendsendsmovndonlyonomonl


More Tutorials from this section

Ask Questions?    Discuss: Trim String Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.