This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

methods()

 
chathuranga
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whath are the difference between

.equals() method & == operator

I have reffered some topics in API but i have been not find such good results.

would you solve this problem
 
Stevi Deter
Ranch Hand
Posts: 265
Hibernate Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chathuranga,

When talking about objects, "==" compares references, not values.

"equals()" compares values for equality. Unless equals() is overridden, the default implementation from Object, which merely uses "==".

A useful summary can be found here.
 
arulk pillai
Author
Ranch Hand
Posts: 3380
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a very important concept to learn and I have covered this along with other fundamentals, with diagrams in a Q&A approach if you want to learn more.
 
adi narayana
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Test{
public static void main(String args[])
{
String s1="hello";
String s2=new String("hello");
if(s1 == s2)
System.out.println("both are same");
else
System.out.println("not same");
}
}
1) equals() method compare the content of the string
2) == operator compares the reference of the string objects
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, adi, but you appear to have missed our naming policy onm the way in. Please click "my profile" and correct your displayed name to conform.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic