Results 1 to 2 of 2
  1. #1
    DrMath is offline Member
    Join Date
    Sep 2009
    Posts
    10
    Rep Power
    0

    Default == is same as .equals()??

    == is same as .equals() ??

    Hi, i not sure how are they different?
    Understanding now is that one looks in deeper when doing the compare?
    Any good examples i can reference?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

    Default

    Equality - as Orwell famously observed - is a matter of interpretation.

    Say you found a $100 note in the street and, the next day, found the same thing. Are they really "the same"? Mostly we would say they are: they both have the same value and all that matters with banknotes is that value. They are equal.

    Not so if were worried about the actual - physical - bank notes themselves. If they were stolen in a robbery, say. Then it might be very significant if a $100 note spent by a "suspect" as "the same as" one of the stolen ones.

    In general the class itself will define what "equality" - or being the same - means. It does this with its .equals() method.

    == tests whether two references refer to the same object in a very strong sense: that of identity. If the objects were created with different uses of "new" then they will not compare equal with ==. This test has nothing to do with what the type itself defines equality to be.
    Last edited by pbrockway2; 09-30-2009 at 06:00 AM.

Similar Threads

  1. equals method
    By mani_miit in forum Advanced Java
    Replies: 7
    Last Post: 09-09-2009, 11:26 PM
  2. equals method
    By timkd127 in forum New To Java
    Replies: 2
    Last Post: 01-24-2009, 07:52 PM
  3. Does retainAll use equals ?
    By Paul Richards in forum Advanced Java
    Replies: 1
    Last Post: 10-27-2008, 09:17 PM
  4. a little problem with (equals)
    By gamilah in forum New To Java
    Replies: 5
    Last Post: 10-25-2008, 05:08 AM
  5. Replies: 0
    Last Post: 01-26-2008, 12:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •