Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <T> Set<T> toTreeSet(Collection<T> collection, Comparator<T> comparator) { final Set<T> treeSet = new TreeSet<>(comparator); for (T t : collection) { treeSet.add(t); } return treeSet; } }