Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

equals() method in String and wrapper classes..

 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


the above is used to override an equals() method from some class.

String and wrapper classes have override the equals method in Object class.

did they have identical implementation of method which is shown above....?
 
mani vannan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the java.lang.String class has similar implementation as above. Please read the source code of equals() here.
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.
what about wrapper classes?

 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrapper classes also follow a similar syntax. If the type of the argument passed and the value of the argument are the same as the one on which it is called, then the output will be true.

eg
new Integer(10).equals(new Integer(10)); //true
new Integer(10).equals(new Float(10)); //false
new Integer(10).equals(new Integer(20)); //false
 
M Srilatha
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the implementation of equals() method in Integer:



And other wrapper classes will also have the same kind of implementation.
Hope this helps!
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for everyone...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic