my dog learned polymorphism
The moose likes Beginning Java and the fly likes trim() function  regardings... 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 » Java » Beginning Java
Bookmark "trim() function  regardings..." Watch "trim() function  regardings..." New topic

trim() function regardings...

Ramesh Balakrishnan

Joined: Mar 19, 2004
Posts: 4
hello people,
I have a doubt in trim() function. I executed the following codelet.
String s="ram".trim();
String k="ram ".trim();
I got "no" output..
if I use equals() function in if checking then I get "yes" output.Please let me know the things happen here.
Ben Buchli
Ranch Hand

Joined: Mar 26, 2004
Posts: 83
always use string1.equalsTo( string2 ) or string1.equalsIgnoreCase( string2 ) when comparing Strings.
I'm sure it will work if you try it like that.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Elouise Kivineva
Ranch Hand

Joined: Feb 07, 2002
Posts: 154
The important thing here is that when you compare two objects (NOTE: Strings are objects, not primitives) using == you are asking whether these two objects are located at the exact same space in the computer's memory, i.e. are the physically one and the same object. You are NOT asking if they are two different objects of logically equal value.
I agree. Here's the link:
subject: trim() function regardings...
It's not a secret anymore!