Source Code:
public class TestSB{
public static void main(String args[]){
String s1="Arnold";
StringBuffer sb1=new StringBuffer("Arnold");
StringBuffer sb2=new StringBuffer("Arnold");
System.out.println(sb1==sb2);
System.out.println(sb1.equals(sb2)); //should be true but printing false
System.out.println(sb1.equals(s1)); //should be true but printing false
}
}
Above is a Source Code that I have written, the output for line 7 and line 8 both should be true but it is coming false what is the reason behind this?
Output:
false
false
false