aspose file tools*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trim() function  regardings..." Watch "trim() function  regardings..." New topic
Author

trim() function regardings...

Ramesh Balakrishnan
Greenhorn

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();
if(s==k)
System.out.println("yes");
else
System.out.println("no");
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.
Ben
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
http://mindprod.com/jgloss/gotchas.html#COMPARISON


[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.
 
Don't get me started about those stupid light bulbs.
 
subject: trim() function regardings...
 
Similar Threads
string question
hast table and unlimited looping
Counting words in a String
q from abhilash mock exam on strings.
Help needed on intern(), compile time Vs run time