Java examples for java.util:Collection to List
Returns collection as sorted ArrayList
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; public class Main { public static void main(String[] argv) { Collection collection = java.util.Arrays.asList("asdf", "java2s.com"); System.out.println(asSortedList(collection)); }/*w w w. ja v a 2s .co m*/ /** * Returns collection as sorted ArrayList * * @param collection * @return sorted list */ public static <T extends Comparable<? super T>> List<T> asSortedList( Collection<T> collection) { List<T> list = new ArrayList<T>(collection); Collections.sort(list); return list; } }