In Java, the TreeSet is a special implementation of Set interface to store unique objects in sorted order. By default it stores the objects in ascending order by performing simple compare. There are couple of ways to use the TreeSet as per our requirement. Here we would discuss about few most commonly used ways. First the simple implementation, then using Comparator and Comparable interface. 1. Storing simple objects import java.