import java.util.HashSet;
import java.util.Iterator;

public class HashSetEx1 {
	public static void main(String[] args) {
		HashSet hs1 = new HashSet();
		HashSet hs2 = new HashSet();
		HashSet hs3;

		hs1.add( new String("a") );
		hs1.add( new String("b") );
		hs1.add( new String("c") );

		hs2.add( new String("c") );
		hs2.add( new String("d") );
		hs2.add( new String("e") );

		System.out.println("hs1="+hs1.toString() );
		System.out.println("hs2="+hs2.toString() );

		//union
		hs3 = new HashSet( hs1 );
		hs3.addAll(hs2);
		System.out.println("UNION(hs1,hs2)="+hs3.toString() );

		hs3 = null;
		//difference
		hs3 = new HashSet( hs1 );
		hs3.removeAll( hs2 );
		System.out.println("hs1 WITHOUT hs2 ="+hs3.toString() );

		hs3 = null;
		//intersection
		hs3 = new HashSet( hs1 );
		hs3.retainAll( hs2 );
		System.out.println("INTERSECTION(hs1,hs2)="+hs3.toString() );

		hs3 = null;
		//symmetric difference
		hs3 = new HashSet( hs1 );
		hs3.addAll( hs2 );
		HashSet tmp1 = new HashSet( hs1 );
		tmp1.retainAll( hs2 );
		hs3.removeAll( tmp1 );
		System.out.println("Symmtetric Difference(hs1,hs2)="+hs3.toString() );

		hs3 = null;
		//cartesian product
		hs3 = new HashSet();
		String c1;

		for( Iterator hs1It = hs1.iterator(); hs1It.hasNext(); ) {
			c1 = hs1It.next().toString();
			for( Iterator hs2It = hs2.iterator(); hs2It.hasNext(); )
			{
				hs3.add( new String( c1 + (hs2It.next()).toString() ) );
			} //for
		} //while
		System.out.println("Cartesian Product(hs1,hs2)="+hs3.toString() );
	} //main()
} //class HashSetEx1