Java Array Sort sort(O[] array)

Here you can find the source of sort(O[] array)

Description

Sorts the given array by its natural order of objects and then returns it, assuming the natural order of the elements follows the Comparable contract.

License

Open Source License

Parameter

Parameter Description
array the array to sort

Return

the given array after sorting it

Declaration

public static <O extends Comparable<O>> O[] sort(O[] array) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    /**/* www  . j  ava  2  s .  c  o m*/
     * Sorts the given array by its natural order of objects and then returns it, assuming the natural order of the elements follows the {@link Comparable} contract.
     * @param array the array to sort
     * @return the given array after sorting it
     */
    public static <O extends Comparable<O>> O[] sort(O[] array) {
        Arrays.sort(array);
        return array;
    }

    /**
     * Sorts the given array by the order dictated by the comparator and then returns it, assuming the Comparator follows the {@link Comparable} contract.
     * @param array the array to sort
     * @param comparator the Comparator to sort the elements by
     * @return the array after sorting it
     */
    public static <O> O[] sort(O[] array, Comparator<? super O> comparator) {
        Arrays.sort(array, comparator);
        return array;
    }
}

Related

  1. Sort(int[] in)
  2. sort(int[] intValues)
  3. sort(int[] keys, int[] values)
  4. sort(int[] values)
  5. sort(Number[] array)
  6. sort(Object[] a)
  7. sort(Object[] arr, int start, int end)
  8. sort(Object[] array)
  9. sort(Object[] array, Comparator comparator)