· The TreeSet class also implements Set interface and uses a tree for data storage.
· Objects are stored in sorted, ascending order and therefore accessing and retrieving an object is much faster.
Example:
import java.util.TreeSet;
class TreeSetDemo
{
public static void main ( String []args)
{
TreeSet objTree = new TreeSet();
objTree.add("beta");
objTree.add("gama");
objTree.add("tera");
objTree.add("alpha");
objTree.add("penta");
System.out.println("Automatically sorted contents of the Tree : \n" + objTree);
}
}
0 comments :
Post a Comment