View RSS Feed

My Java Tips

  1. Using Treeset

    by , 11-13-2011 at 12:29 PM (My Java Tips)
    TreeSet belongs to Java Collection Framework and is very rare situations. In this post, I will briefly discuss when to use TreeSet and how to use it.

    To use it, you have to import java.util.TreeSet in your class. TreeSet is not synchronized so if a TreeSet is concurrently accessed by threads then thread modifying the contents must be synchronized externally. TreeSet provides following constructors:
    TreeSet(Collection c)
    TreeSet(Comparator c)
    TreeSet(SortedSet ...