Java Array Sort toSortedArray(Collection collection)

Here you can find the source of toSortedArray(Collection collection)

Description

to Sorted Array

License

Open Source License

Declaration

public static <T extends Comparable<?>> Object[] toSortedArray(Collection<T> collection) 

Method Source Code

//package com.java2s;

import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;

public class Main {
    public static <T extends Comparable<?>> Object[] toSortedArray(Collection<T> collection) {
        Object[] result = collection.toArray();
        Arrays.sort(result);/* w ww .jav  a  2 s  . c  o m*/
        return result;
    }

    @SuppressWarnings("unchecked")
    public static <T> Object[] toSortedArray(Collection<T> collection, Comparator<T> cmp) {
        Object[] result = collection.toArray();
        Arrays.sort(result, (Comparator<Object>) cmp);
        return result;
    }
}

Related

  1. sortTwoArrays(A[] firstArray, B[] secondArray)
  2. sortWith(final int[] ary, int[] ary2)
  3. SortWithIndex(double[] arr, Integer[] i)
  4. sortWithInds(int[] x, int[] idx)
  5. sortWithNoMissingValues( double[] array)
  6. toSortedArray(Set groups)
  7. toSortedIntArray(Collection ints)
  8. toStringArray(Collection collection, boolean sort)
  9. union(int[] sorted1, int[] sorted2)