Results 1 to 18 of 18
  1. #1
    james12 is offline Member
    Join Date
    Jun 2014
    Posts
    37
    Rep Power
    0

    Default Difference between equals() method and == operator?

    hi any one please let me know the difference between equals() and == operator

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,874
    Rep Power
    5

    Default Re: Difference between equals() method and == operator?

    Here is an exercise for you: try a Google for "java difference between equals and ==".

    It is actually quite simple and fast to get a quick answer to these kind of trivia questions, but it is quite difficult and time consuming to explain it all. So please, first try to find the answer using Google as thousands of people before you have already asked this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: Difference between equals() method and == operator?

    @OP: don't post those utter beginners' homework question in the Advanced Java forum; I move it.

    kind regards,

    Jo
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default Re: Difference between equals() method and == operator?

    1. What's the point of copy/pasting the entire text of that page when you provided the link, especially since you have added nothing to the content?
    2. The OP didn't specifically ask about Strings, though the general point holds. So the explanation might come across as specifically about Strings and not '==' and 'equals()' in general.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: Difference between equals() method and == operator?

    Maybe the poster wants to dump his entire tutorial here; piece by piece; this forum might be his own poor man's cloud ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,874
    Rep Power
    5

    Default Re: Difference between equals() method and == operator?

    I wonder what's worse: a 'normal' spammer or an 'on-topic spammer' who only wants to upgrade his search scores on Google.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: Difference between equals() method and == operator?

    Quote Originally Posted by gimbal2 View Post
    I wonder what's worse: a 'normal' spammer or an 'on-topic spammer' who only wants to upgrade his search scores on Google.
    Nah, I don't really care; the only reason that poster has kept me in doubt is that 'his' answers sort of make sense; the link (removed by Tolls) is the irritating part; to be sure I started the engine of the rotating knives machine ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,874
    Rep Power
    5

    Default Re: Difference between equals() method and == operator?

    Its also the behavior that is irritating; just running through a series of posts with easy topics, no matter how old and no matter if the answer is already given or not, looking for places to spam a link.

    Hack away, please!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default Re: Difference between equals() method and == operator?

    He's been warned, so hopefully will show some restraint.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: Difference between equals() method and == operator?

    Quote Originally Posted by Tolls View Post
    He's been warned, so hopefully will show some restraint.
    I couldn't resist and fed him to the rotating knives machine; it was a fascinating sight: first he was immobilized, his eyes poked out, his knee caps ruined and the instestins removed; the conveyor belt transported him to the rotating knives and now the bloody remnants are neatly collected in buckets labeled 'spam'.

    kindest regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,874
    Rep Power
    5

    Default Re: Difference between equals() method and == operator?

    Amazing how that is exactly like a scene from the movie 'Saw VI'.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: Difference between equals() method and == operator?

    Quote Originally Posted by gimbal2 View Post
    Amazing how that is exactly like a scene from the movie 'Saw VI'.
    How strange, because I wanted to make it resemble a scene from 'Me and My Little Pony'. What made you feel it resembles that silly butcher movie? (I just looked it up on youtube and I'm not hungry anymore; thank you for that).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: Difference between equals() method and == operator?

    Quote Originally Posted by JosAH View Post
    I couldn't resist and fed him to the rotating knives machine; it was a fascinating sight: first he was immobilized, his eyes poked out, his knee caps ruined and the instestins removed; the conveyor belt transported him to the rotating knives and now the bloody remnants are neatly collected in buckets labeled 'spam'.
    Aha! I was going back and forth trying to figure out what you guys were talking about. Quite a few of the replies don't make sense now.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  14. #14
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,874
    Rep Power
    5

    Default Re: Difference between equals() method and == operator?

    You're too late, we already fought over and consumed all the tasty bits out of this carcass.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    Join Date
    Jul 2014
    Location
    United States
    Posts
    7
    Rep Power
    0

    Default Re: Difference between equals() method and == operator?

    Main difference between '==' and equals() in Java is that '==' is a operator used to check whether two different reference refers to same instance and equals() is a method used to check equality of an object. Another important difference is '==' operators is used more with primitive data type while equals() method is used for object.

    Regards

    [ ad links removed -- mod ]
    Last edited by JosAH; 07-02-2014 at 09:34 AM.

  16. #16
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,932
    Rep Power
    8

    Default Re: Difference between equals() method and == operator?

    Quote Originally Posted by gimbal2 View Post
    I wonder what's worse: a 'normal' spammer or an 'on-topic spammer' who only wants to upgrade his search scores on Google.
    Hey! Stop talking about me!

    (visit StaticVoidGames.com)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  17. #17
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,874
    Rep Power
    5

    Default Re: Difference between equals() method and == operator?

    he he he :) Well at least you admit it!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  18. #18
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

    Default Re: Difference between equals() method and == operator?

    Quote Originally Posted by gimbal2 View Post
    he he he :) Well at least you admit it!
    Wouldn't catch me doing that...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Difference between operator and method
    By jmohandos304 in forum New To Java
    Replies: 1
    Last Post: 06-04-2014, 02:03 PM
  2. Replies: 10
    Last Post: 02-12-2013, 11:00 AM
  3. Difference between == and equals()
    By meenakshipuni in forum New To Java
    Replies: 4
    Last Post: 11-16-2011, 03:30 AM
  4. ArrayLists compareTo method, equals method
    By random0munky in forum New To Java
    Replies: 2
    Last Post: 10-26-2009, 07:20 PM

Posting Permissions

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