This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes trim( ) method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "trim( ) method" Watch "trim( ) method" New topic

trim( ) method

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
System.out.println("aa aa".trim());

why the output of this statement is :
aa aa

please help ...
thanks .
Lakshmi Keshav

Joined: Jan 17, 2005
Posts: 7
trim() method removes only leading or trailing blank spaces. Not the spaces in between.
Dave Lenton
Ranch Hand

Joined: Jan 20, 2005
Posts: 1241
String.trim() just removes leading and trailing spaces (i.e. spaces at the start and end of the String). "aa aa" doesn't have any leading or trailing spaces, so gets returned as it is.

There will be glitches in my transition from being a saloon bar sage to a world statesman. - Tony Banks
marc weber

Joined: Aug 31, 2004
Posts: 11343

rathi, you can find the answers to many of your questions in the API Specs.
[ January 21, 2005: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: trim( ) method
It's not a secret anymore!