Results 1 to 5 of 5
- 11-12-2011, 02:18 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 5
- Rep Power
- 0
Difference between == and equals()
Hi Every One,
Can anyone explain me the difference between equality operator (==) and equals() method.
I am jus trying the following code... please explain me.
String s = new String("abc");
String s1 = new String("abc");
System.out.println("String Equals : "+s==s1); // It returns false
System.out.println("String Equals Opr: "+s.equals(s1));//It return true.
Thanks in advance
- 11-12-2011, 03:48 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,602
- Blog Entries
- 7
- Rep Power
- 17
Re: Difference between == and equals()
Suppose you and I are pointing to the same, say, television set; the == operator returns true because we're both pointing to one television set. Now, suppose we're both pointing to two different sets. The == operator will return false but the equals( ... ) method might return true if both television sets are the same brand, the same size etc.
kind regards.
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-12-2011, 05:54 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 5
- Rep Power
- 0
Re: Difference between == and equals()
Thanks for ur valuable explanation...
- 11-15-2011, 09:30 AM #4
Member
- Join Date
- Nov 2011
- Posts
- 28
- Rep Power
- 0
Re: Difference between == and equals()
== for primitive type comparisons
.equals() for object comparisons
- 11-16-2011, 03:30 AM #5
Similar Threads
-
c always equals a*b
By imorio in forum New To JavaReplies: 3Last Post: 11-12-2010, 02:32 PM -
== and equals()
By arefeh in forum New To JavaReplies: 13Last Post: 01-05-2010, 04:56 PM -
== is same as .equals()??
By DrMath in forum New To JavaReplies: 1Last Post: 09-30-2009, 04:57 AM -
name clash: equals(E) in and equals(java.lang.Object)
By AdRock in forum New To JavaReplies: 0Last Post: 01-25-2008, 11:13 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks