public <E> void algo1(TreeSet<E> A, TreeSet<E> B) { for (E x : A) if (B.contains(x)) B.remove(x); code example
Example: java treeset
import java.util.*;
// Declare the variable using the interface of the object for flexibility.
// Non-primative data types only.
Set<String> movies = new TreeSet<String>();
movies.add(E);
// TreeSet will be sorted by element.
// Work with any comparable object.
movies.add("The Shining");
movies.add("Dawn of the Dead");
movies.add("Zombieland");