wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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.
subject: trim() function regardings...
Similar Threads
Counting words in a String
q from abhilash mock exam on strings.
hast table and unlimited looping
string question
Help needed on intern(), compile time Vs run time