Java examples for java.util:Collection Convert
Convert a Collection of T to a sorted List of T.
//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 ww .j a v a2s .c o m /** * Convert a {@link Collection} of <T> to a sorted {@link List} of <T>. */ public static <T extends Comparable<T>> List<T> asSortedList( final Collection<T> collection) { final List<T> list = new ArrayList<>(collection); Collections.sort(list); return list; } }