Here you can find the source of collectionToSortedArray(Collection extends Object> objects)
public static Object[] collectionToSortedArray(Collection<? extends Object> objects)
//package com.java2s; /**/* w w w . j av a 2 s . c om*/ * This file is licensed under the University of Illinois/NCSA Open Source License. See LICENSE.TXT for details. */ import java.util.Arrays; import java.util.Collection; import java.util.Comparator; public class Main { public static Object[] collectionToSortedArray(Collection<? extends Object> objects) { Object[] sortedArray = objects.toArray(new Object[] {}); Arrays.sort(sortedArray, new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { return o1.toString().compareTo(o2.toString()); } }); return sortedArray; } }