Here you can find the source of intersection(TreeSet
public static TreeSet<String> intersection(TreeSet<String> AL1, TreeSet<String> AL2)
//package com.java2s; //License from project: Apache License import java.util.TreeSet; public class Main { public static TreeSet<String> intersection(TreeSet<String> AL1, TreeSet<String> AL2) { TreeSet<String> returnTreeSet = new TreeSet<String>(); for (String test : AL1) { if (!returnTreeSet.contains(test)) { if (AL2.contains(test)) { returnTreeSet.add(test); }//from ww w. jav a 2 s.c om } } return returnTreeSet; } }