• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

equal/== help

 
Jason sigel
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suppose the replace method of String class returns an Internalized String, which refer to an existing Similar String if it exists
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic