interface Set { boolean contains(A x); Set include(A x); } abstract class LinkedList implements Set { public abstract boolean contains(A x); public LinkedList insert(A x) { if (contains(x)) return this; else return new NonEmptyList(x, this); } public Set include(A x) { return insert(x); } } class EmptyList extends LinkedList { public boolean contains(A x) { return false; } } class NonEmptyList extends LinkedList { private A elem; private LinkedList rest; public NonEmptyList(A elem, LinkedList rest) { this.elem = elem; this.rest = rest; } public boolean contains(A x) { return ((Object)elem).equals((Object)x) || rest.contains(x); } } public class TestForDuplicates { public static void main(String[] args) { Set set = new EmptyList(); for (int i = 1; i < args.length; i++) set = set.include(args[i]); System.out.println(set.contains(args[0])); } }