aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes equal/==  help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "equal/==  help" Watch "equal/==  help" New topic
Author

equal/== help

Jason sigel
Ranch Hand

Joined: Oct 07, 2003
Posts: 30
Replace return a new string .In the code
class aja{
public static void main(String[] args){
if("String".replace('t','t') =="String")
System.out.println("Equal");
else
System.out.println("Not Equal");
}
}
what I know is equals checks the value in object refernce whereas == checks the reference of the object.
class aja{
public static void main(String[] args){
if("String".replace('t','t') .equals("String"))
System.out.println("Equal");
else
System.out.println("Not Equal");
}
}

why first code is returning equal.Please correct me.
jaideep
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I suppose the replace method of String class returns an Internalized String, which refer to an existing Similar String if it exists
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: equal/== help
 
Similar Threads
String Doubts
Stirngs again... why this happens ?
String literals
String Confusion
Java Strings