File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes == operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "== operator" Watch "== operator" New topic

== operator

Soum Sark
Ranch Hand

Joined: May 31, 2002
Posts: 50
What are the general rules governing the use of the == operator. I notice we cannot compare
String == StringBuffer . Why is this. Do the objects on both sides have to be in some sort of hierarchy ?
Nate Johnson
Ranch Hand

Joined: May 13, 2002
Posts: 301
== usually compares two objects as pointing to the same reference.
even if you had ...
String a = new String("A");
String b = new String("A");
you should get false when you say...
System.out.println(a == b);

scwcd, scjd, scjp<br /><a href="" target="_blank" rel="nofollow"></a><br /><a href="" target="_blank" rel="nofollow"></a>
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

Please don't post duplciate threads.
Reply to the Original thread.
I agree. Here's the link:
subject: == operator
It's not a secret anymore!