Untitled Document

Subscribe here to get updates on new Videos


32. TreeSetDetails part 2?




previous homenext



1. If we are depending on default natural sorting order then objects should be homogeneous and comparable. Otherwise we will get runtime exception saying ClassCastException.
2. An Object is Said to be comparable if and only if the corresponding class implements java.lang.comparable interface.
3. String class and all wrapper classes already implements comparable interface. But StringBuffer doesn’t implement comparable interface.
** Hence in the above program we got ClassCastException