Here you can find the source of toSortedList(Collection
public static <T extends Comparable<T>> List<T> toSortedList(Collection<T> collection)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Main { public static <T extends Comparable<T>> List<T> toSortedList(Collection<T> collection) { List<T> list = new ArrayList<T>(); list.addAll(collection);/*w ww. j av a2 s . c om*/ Collections.sort(list); return list; } public static <T extends Comparable<T>> List<T> toSortedList(Collection<T> values, int top) { List<T> list = toSortedList(values); List<T> topList = new ArrayList<T>(); for (int i = 0; i < top && i < list.size(); i++) { topList.add(list.get(i)); } return topList; } public static <T> void addAll(T[] array, List<T> list) { for (T t : array) { list.add(t); } } }