Here you can find the source of sort(Collection collection)
@SuppressWarnings({ "rawtypes", "unchecked" }) public static void sort(Collection collection)
//package com.java2s; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; public class Main { @SuppressWarnings({ "rawtypes", "unchecked" }) public static void sort(Collection collection) { if (isNotEmpty(collection)) { Object[] objs = collectionToArray(collection); Arrays.sort(objs);// w w w . java 2 s . com collection.clear(); collection.addAll(arrayToCollection(objs)); } } public static void sort(Object[] objs) { if (isNotEmpty(objs)) { Arrays.sort(objs); } } @SuppressWarnings("rawtypes") public static boolean isNotEmpty(Map map) { return !isEmpty(map); } @SuppressWarnings("rawtypes") public static boolean isNotEmpty(Collection collection) { return !isEmpty(collection); } public static boolean isNotEmpty(Object[] objs) { return !isEmpty(objs); } @SuppressWarnings({ "rawtypes", "unchecked" }) public static Object[] collectionToArray(Collection collection) { Object[] objs = null; if (isNotEmpty(collection)) { objs = new Object[collection.size()]; collection.toArray(objs); } return objs; } @SuppressWarnings({ "rawtypes", "unchecked" }) public static List arrayToCollection(Object[] objs) { return new ArrayList(Arrays.asList(objs)); } @SuppressWarnings("rawtypes") public static boolean isEmpty(Map map) { if (map == null || map.size() == 0) { return true; } return false; } @SuppressWarnings("rawtypes") public static boolean isEmpty(Collection collection) { if (collection == null || collection.size() == 0) { return true; } return false; } public static boolean isEmpty(Object[] objs) { if (objs == null || objs.length == 0) { return true; } return false; } }