Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

== operator

 
Soum Sark
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
thanx
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
== 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);
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post duplciate threads.
Reply to the Original thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic