Java String Class implements Comparable interface, but StringBuilder and StringBuffer do not implement Comparable Interface
Hi I am trying to add a StringBuffer object to a treeet, but I got a ClassCastException because StringBuffer does not implement the Comparable Interface that String does. I would like to know why StringBuffer and StringBuilder do not implement the Comparable interface implicitly.
TreeSet s = new TreeSet();
s.add(new StringBuffer("A"));
s.add(new StringBuffer("B"));
+3
source to share
No one has answered this question yet
See similar questions:
or similar: