Java tutorial
//package com.java2s; import java.util.Iterator; import java.util.Set; import java.util.TreeSet; public class Main { public static <T> Set<T> toSet(final Iterable<T> iterable) { final Set<T> set = new TreeSet<T>(); for (Iterator<T> i = iterable.iterator(); i.hasNext();) { set.add(i.next()); } return set; } }