Objects are sorted in ascending order.
Access time is much more faster.
It prevents duplicates.
TreeSet uses the objects compareTo() to sort the objects.
Example:
import java.util.*;
class demo
{
public static void main(String[] args){
TreeSet
ts.add("k");
ts.add("e");
ts.add("a");
ts.add("i");
ts.add("q");
ts.add("m");
ts.add("g");
System.out.println(ts);
};
Output:
a,e,g,I,k,q //in sorted order
No comments:
Post a Comment