If we see the
Java documentation. Then both the classes are extending Object class and they have no relationship with each other excpet that they are both the members of same package. And both are used to represent strings. String class is used to represent immutable strings while string buffer class is used to represent mutable strings. If you call the toString method of the StringBuffer class and then pass the resulting object to equals method. Then it also returns true.
String s = "hi";
String ss = new String("hi");
StringBuffer sb = new StringBuffer("hi");
s.equals(ss) -------> true
s.equals(sb.toString()) -------> true
Regards
Muhammad Ali