Here you can find the source of sortedByName(Collection
private static <T> List<T> sortedByName(Collection<T> unsorted, Comparator<T> comparator, T... exclusions)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Main { private static <T> List<T> sortedByName(Collection<T> unsorted, Comparator<T> comparator, T... exclusions) { if (unsorted == null) { return Collections.emptyList(); }/*from w w w . ja va 2 s .c o m*/ List<T> retList = removeExclusionsFrom(unsorted, comparator, exclusions); Collections.sort(retList, comparator); return retList; } private static <T> List<T> removeExclusionsFrom(Collection<T> collectionOfT, Comparator<T> comparator, T... exclusions) { List<T> retList = new ArrayList<>(); for (T t : collectionOfT) { boolean excluded = false; for (T excludedT : exclusions) { if (comparator.compare(t, excludedT) == 0) { excluded = true; break; } } if (!excluded) { retList.add(t); } } return retList; } }