import java.util.*;

public class OrderednessOfImplementationLeaksThroughCollectionInterface
{
	public static void is_equal(String name1, String name2, Collection c1, Collection c2)
	{
		System.out.print(name1+" is ");
		if (!c1.equals(c2)) System.out.print("not ");
		System.out.println("equal to "+name2);
	}

	public static void main (String[] args)
	{
		Collection<Integer> al1 = new ArrayList<Integer>();
		Collection<Integer> al2 = new ArrayList<Integer>();
		Collection<Integer> al3 = new ArrayList<Integer>();
		al1.add(1); al1.add(2);
		al2.add(1); al2.add(2);
		al3.add(2); al3.add(1);
		Collection<Integer> hs1  = new HashSet<Integer>(al1);
		Collection<Integer> hs2  = new HashSet<Integer>(al2);
		Collection<Integer> hs3  = new HashSet<Integer>(al3);
		Collection<Integer> ts1  = new TreeSet<Integer>(al1);
		Collection<Integer> ts2  = new TreeSet<Integer>(al2);
		Collection<Integer> ts3  = new TreeSet<Integer>(al3);

		is_equal("al1", "al2", al1, al2);
		is_equal("al1", "al3", al1, al3);
		is_equal("hs1", "hs2", hs1, hs2);
		is_equal("hs1", "hs2", hs1, hs2);
		is_equal("ts1", "ts3", ts1, ts3);
		is_equal("ts1", "ts3", ts1, ts3);
	}
}

/* Output:

al1 is equal to al2
al1 is not equal to al3
hs1 is equal to hs2
hs1 is equal to hs2
ts1 is equal to ts3
ts1 is equal to ts3

 * One can tell whether the underlying implementation of Collection,
 * even when accessed only through the Collection interface, sorts
 * its elements upon construction. */

