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.
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.