MyInterface.java

import java.util.List;

interface MyInterface<Element> {
  public boolean containsBoth(Element a, Element b);
}

MyList.java

import java.util.*;

public class MyList<Element> extends LinkedList<Element> 
                    implements MyInterface<Element> {

  public boolean containsBoth(Element a, Element b) {
    return (contains(a) && contains(b));
  } 

  public static <A> void swap(List<A> list, int i, int j) {
    A temp = list.get(i); 
    list.set(i, list.get(j));
    list.set(j, temp);
  } 

   /*
   ** main
   */
  public static void main( String[] args) {

    // create list and add elements
    MyList<String> theList = new MyList<String>();

    theList.add("one");
    theList.add("two");
    theList.add("three");

    // print out the list's contents
    System.out.println("");
    System.out.println("The list's contents are:");
    ListIterator<String> theIterator= theList.listIterator(0);
    while (theIterator.hasNext()) {
      System.out.println(theIterator.next());
    }
    System.out.println("");

    // use the containsBoth method
    if (theList.containsBoth("one", "two")) {
      System.out.println("The list contains both \"one\" and \"two\"");
    }

    // use the swap method
    swap(theList, 0, 2); 
      
    // print out the list's contents
    System.out.println("");
    System.out.println("The list's contents are:");
    theIterator = theList.listIterator(0);
    while (theIterator.hasNext()) {
      System.out.println(theIterator.next());
    }
    System.out.println("");
 
   } // main

} // MyList