import java.util.TreeSet; public class SetDemo { public static void main(String[] args) { //Demo Tree Set TreeSet ts = new TreeSet ( ) ; System.out.println ( ts.isEmpty ( ) ) ; ts.add ( "Chicago" ) ; ts.add ( "Mumbai" ) ; ts.add ( "Delhi" ) ; ts.add ( "NY" ) ; ts.add ( "Chicago" ) ; for (String item: ts) { System.out.println ( "city: " + item ) ; } //Experimenting with some basic operations System.out.println ( ts.isEmpty ( ) ) ; System.out.println ( ts.size ( ) ) ; System.out.println ( "Does it contain Delhi "+ts.contains ( "Delhi" ) ) ; System.out.println ( "Adding Paris "+ts.add ( "Paris" ) ) ; System.out.println ( "have you removed NY " + ts.remove ( "NY" ) ) ; //Experimenting with some bulk operations TreeSet coll = new TreeSet ( ) ; coll.add ( "SLO" ) ; coll.add ( "NY" ) ; System.out.println ( "Does it contain ny, SLO "+ts.containsAll ( coll ) ) ; System.out.println ( "Has it added ny, SLO "+ts.addAll ( coll ) ) ; System.out.println ( "have you removed NY " + ts.remove ( "NY" ) ) ; for (String item: ts) { System.out.println ( "city: " + item ) ; } } } /* OUTPUT true city: Chicago city: Delhi city: Mumbai city: NY false 4 Does it contain Delhi true Adding Paris true have you removed NY true Does it contain ny, SLO false Has it added ny, SLO true have you removed NY true city: Chicago city: Delhi city: Mumbai city: Paris city: SLO */