default treeset java code example
Example 1: TreeSet size() method in java
import java.util.TreeSet;
public class TreeSetSizeMethodExample
{
public static void main(String[] args)
{
TreeSet ts = new TreeSet();
ts.add("watermelon");
ts.add("apple");
ts.add("banana");
ts.add("grapes");
ts.add("mango");
ts.add("orange");
System.out.println("Given TreeSet: " + ts);
// print size of TreeSet
System.out.println("size of TreeSet is: " + ts.size());
}
}
Example 2: treeset
TreeSet: Can contain only unique values and it is sorted in ascending order
TreeMap: Can contain only unique keys and keys are sorted in ascending order.