Results 1 to 11 of 11
Like Tree4Likes
  • 2 Post By Vamsi Priya
  • 1 Post By JosAH
  • 1 Post By DarrylBurke

Thread: what is the difference b/w "==" and equals() in java ? which one is better to use

  1. #1
    Reddi.Java is offline Member
    Join Date
    Dec 2012
    Location
    India
    Posts
    6
    Rep Power
    0

    Post what is the difference b/w "==" and equals() in java ? which one is better to use

    Hello All,

    what is the difference b/w "==" and equals() in java ? which one is better to use in string with example.

    Regards,
    Reddi

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,050
    Rep Power
    20

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    What do you think?
    This sounds rather like homework.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    You didn't bother to reply to PhHein's response in your first thread, and I see no reason to expect better behavior here.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    What is advanced about this question? It is Java 101

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    Vamsi Priya is offline Member
    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    "==" and equals() both compare if the objects reference variables refer to the same instance of an object.
    But the equals() method can be over-ridden. For example, an employee class may have an equals method which makes two employee reference variables equal if
    their employeeId's are equal. Consider
    Employee emp1 = new Employee();
    Employee emp2 = new Employee();
    emp1.equals(emp2) is true if the employeeId's are equal but emp1==emp2 is not true. So when ever u need to specify a custom condition for equality u can over ride equals() and use it. Do remember that u have to over ride hashcode() when ever equals() is over ridden.
    Kagiso and sonpham like this.

  6. #6
    Reddi.Java is offline Member
    Join Date
    Dec 2012
    Location
    India
    Posts
    6
    Rep Power
    0

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    Hello priya

    thanks for your quick reply.

    now i am clear of this topic before that i have bit confuse..

  7. #7
    Reddi.Java is offline Member
    Join Date
    Dec 2012
    Location
    India
    Posts
    6
    Rep Power
    0

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    Hello all,

    you know the answer then only reply to thread,otherwise dont post useless comments on thread.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    Most (if not all) of us know the answer to your (elementary) question and you're not the one to decide who is allowed to post a reply or not.

    kind regards,

    Jos
    Kagiso likes this.
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    Reddi.Java is offline Member
    Join Date
    Dec 2012
    Location
    India
    Posts
    6
    Rep Power
    0

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    i think you are thinking that you are the father of java i am correct
    any way no issue thanks for replys this is not correct to communicate out side java discussions..

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,574
    Blog Entries
    7
    Rep Power
    21

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    Quote Originally Posted by Reddi.Java View Post
    i think you are thinking that you are the father of java i am correct
    No you are not correct.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: what is the difference b/w "==" and equals() in java ? which one is better to use

    Quote Originally Posted by Reddi.Java View Post
    this is not correct to communicate out side java discussions..
    Are you really trying to teach members with thousands of posts how to use a forum?

    db
    Kagiso likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  2. Difference between again == "y"; and again.equals("y");
    By sandman18and5 in forum New To Java
    Replies: 5
    Last Post: 07-27-2012, 06:35 PM
  3. Replies: 4
    Last Post: 06-14-2011, 04:59 AM
  4. Replies: 1
    Last Post: 09-08-2010, 04:08 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 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
  •