Write a java program to demonstrate the use of iterator with the Tree Set collection. code example

Example 1: java treeset

import java.util.*;

// Declare the variable using the interface of the object for flexibility.
// Non-primative data types only.
Set<String> movies = new TreeSet<String>();

movies.add(E);
// TreeSet will be sorted by element.
// Work with any comparable object.

movies.add("The Shining");
movies.add("Dawn of the Dead");
movies.add("Zombieland");

Example 2: treeset in java

- TreeSet sorts the order and don't accept null

Tags:

Java Example