FileDocCategorySizeDatePackage
SetStuff.javaAPI DocExample778Sat Mar 16 10:30:38 GMT 2002None

SetStuff

public class SetStuff extends Object
Show the union and instersection of two sets.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


		// Create two sets.
		Set s1 = new HashSet();
		s1.add("Ian Darwin");
		s1.add("Bill Dooley");
		s1.add("Jesse James");

		Set s2 = new HashSet();
		s2.add("Ian Darwin");
		s2.add("Doolin' Dalton");

		Set union = new TreeSet(s1);
		union.addAll(s2);		// now contains the union

		print("union", union);

		Set intersect = new TreeSet(s1);
		intersect.retainAll(s2);

		print("intersection", intersect);

	
protected static voidprint(java.lang.String label, java.util.Collection c)


		System.out.println("--------------" + label + "--------------");

		Iterator it = c.iterator();
		while (it.hasNext()) {
			System.out.println(it.next());
		}