class strb
{
static public void main(String...string)
{
StringBuilder s1 = new StringBuilder(\"Test\");
StringBuilder s2 = new StringBuild
StringBuilder
and StringBuffer
not override the equals function of Object
class.but string override the equals
method.
the function of Object
is this
public boolean equals(Object obj) {
return (this == obj);
}
you could write your code like this.
System.out.println(s1.toString() == s2.toString());
System.out.println(s1.toString().equals(s2.toString()));