Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

treeset sort

TreeSet t=new TreeSet();
t.add("A");
t.add("Z");====>"Z".compareTo("A");(positive) how much positive number it comes?
t.add("A");====>"A".compareTo("B");(negative)//here while jvm doing default natural sorting i thought instead of B, Z has to be compared with A but B is being compared with A since B is root element. What is meaning of root element. why Z is not root element??
System.out.println(t)//comes [A,B,Z} right not [Z,B,A]
how to get custom sorting like Z B A

why StringBuffer does not support default natural sorting. How to sort String Buffer objects.

obj1.compareTo(obj2)//obj2 is already present element in tree set and obj1 is new element being added??

please advise
SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial