Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trim( ) method

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println("aa aa".trim());

why the output of this statement is :
aa aa

please help ...
thanks .
 
Lakshmi Keshav
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
trim() method removes only leading or trailing blank spaces. Not the spaces in between.
 
Dave Lenton
Ranch Hand
Posts: 1241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rathi, you can find the answers to many of your questions in the API Specs.

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
[ January 21, 2005: Message edited by: marc weber ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic