Παράδειγμα της διεπαφής Collection

import java.util.Collection;
import java.util.LinkedList;

public class CollectionTest <E> {
    static <E> void testContain(Collection <E> c, E o) {
        System.out.print("The collection " + c);
        if (c.contains(o))
            System.out.print(" contains");
        else
            System.out.print(" does not contain");

        System.out.println(" the object " + o);
    }

    public static void main(String args[]) {
        var list = new LinkedList <String>();

        list.add("Petros");
        list.add("Maria");

        testContain(list, "Maria");
        testContain(list, "John");
        testContain(list, "Petros");
        System.out.println("Number of elements = " + list.size());
    }
}