Home Java Beginners Trim String Example
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Trim String Example

Advertisement
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
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 8, 2007

Related Tutorials

Ask Questions?    Discuss: Trim String Example   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
POLA
January 16, 2012
yes sir!

ahhhhh!!! very good!
sda
January 25, 2012
asdfasd

<p><b><i><a>this is test<p></b></i></a>
ishak
March 1, 2012
the right side?

What about when the blank is on the right side?
DMCA.com