File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes methods() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "methods()" Watch "methods()" New topic



Joined: Apr 20, 2008
Posts: 4
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

Joined: Mar 22, 2008
Posts: 265


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.

There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
arulk pillai
Ranch Hand

Joined: May 31, 2007
Posts: 3359
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.

[] | [Java job hunting know how] | [Java resumes]
adi narayana

Joined: May 08, 2008
Posts: 2
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");
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

Joined: Oct 13, 2005
Posts: 45338
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.
jQuery in Action, 3rd edition
subject: methods()
It's not a secret anymore!