import java.util.*;
//------------------------------------------------------------------------------
//Creating and using Sets. Set elements must be unique
//------------------------------------------------------------------------------

public class set1 
{
    public static void main(String[] args) 
    {
        //=== Example of using a HashSet =======================================
        //A HashSet returns elements in no particular order

        HashSet<String> Hset = new HashSet<String>();
        boolean ok;

        System.out.println("\n A HashSet: " + Hset);

        ok = Hset.add("Sam");
        System.out.println("added Sam successfully? " + ok);
        ok = Hset.add("John");
        System.out.println("added John successfully? " + ok);

        System.out.println(Hset); 

        ok = Hset.add("Sam");                                   //since this is a duplicate value,              
        System.out.println("added Sam successfully? " + ok);    //it will not be added

        ok = Hset.add("Bill");
        System.out.println("added Bill successfully? " + ok);
                                            
        System.out.println(Hset); 


        //=== Example of using a TreeSet ========================================
        //A TreeSet always returns elements in sort order

        TreeSet<String> Tset = new TreeSet<String>();

        System.out.println("\n A TreeSet: " + Tset);

        ok = Tset.add("Sam");
        System.out.println("added Sam successfully? " + ok);
        ok = Tset.add("John");
        System.out.println("added John successfully? " + ok);
        ok = Tset.add("25");
        System.out.println("added '25' successfully? " + ok);
        ok = Tset.add("false");
        System.out.println("added 'false' successfully? " + ok);

        System.out.println(Tset);                               //printed in sort order 

        ok = Tset.add("Sam");                                   //since this is a duplicate value,              
        System.out.println("added Sam successfully? " + ok);    //it will not be added

        ok = Tset.add("Bill");
        System.out.println("added Bill successfully? " + ok);
                                            
        System.out.println(Tset); 
    }
}