StringBuffer Question.
I am new to
Java programming, please help me with this.
I wanted to check if two
String buffers have same values.
Why should it return unmatch in these cases?
class Sb_Test {
public static void main(String args[]) {
StringBuffer sb1,sb2;
sb1 = new StringBuffer("Raj");
sb2 = new StringBuffer("Raj");
if (sb1.equals(sb2))
{ System.out.println("String buffers match"); }
else
{ System.out.println("String buffers unmatch"); }
if (sb1 == sb2)
{ System.out.println("String buffers match"); }
else
{ System.out.println("String buffers unmatch"); }
/* if (sb1.compareTo(sb2))
{ System.out.println("String buffers match"); }
else
{ System.out.println("String buffers unmatch"); }
doesn't compile */
}
}
Result :
String buffers unmatch
String buffers unmatch
.equals should work, why it doesn't work with Stringbuffers , but works with strings