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

Difference between == and equals() in java

 
Praveen palukuri
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can u give exact difference between == operator and .equals() in java.

Thank You in advance.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"==" asks whether two objects are the same physical object -- the same chunk of memory. "equals()" is a method which by default means the same thing, but can be overridden to ask whether two objects are "the same" by some appropriate definition. For example, two String objects are "the same" if they have the same characters in the same order, even if they are two different physical objects. String overrides equals() to mean this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic