I hope you know why == returns false. It is just doing reference comparison on two distinct objects. Unike String, StringBuffer does not override the equals() method in the Object class. Hence, here equals() is the same as == ie., reference comparison, which returns false in our example. Hope this helps, Ajith
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Hi, 1. StringBuffer sb1 = new StringBuffer("goodday"); 2. StringBuffer sb2= new StringBuffer("goodday"); 3. String ss1 = "goodday"; 4. System.out.println(sb1==sb2); 5. System.out.println(sb1.equals(sb2)); 6. System.out.println(sb1.equals(ss1)); 7. System.out.println("puffdar".substring(3)); Line 4 will be false for obvious reasons, sb1 and sb2 are different objects. Line 5 will be false. StringBuffer class does not override the equals method. So you only have the default method in Object which does nothing more than see if the two references are the same (which happens to be the same as == ). Line 6 will print false because of different objects. Line 7 will print "fdar" (without the quotes). The method prints the rest of the string starting the index position specified (remember the index starts at 0). Hope this helps Ajay Kumar