Sort an array

ReturnMethodSummary
static voidsort(byte[] a)Sorts the specified array of bytes into ascending numerical order.
static voidsort(byte[] a, int fromIndex, int toIndex)Sorts the specified range of the specified array of bytes into ascending numerical order.
static voidsort(char[] a)Sorts the specified array of chars into ascending numerical order.
static voidsort(char[] a, int fromIndex, int toIndex)Sorts the specified range of the specified array of chars into ascending numerical order.
static voidsort(double[] a)Sorts the specified array of doubles into ascending numerical order.
static voidsort(double[] a, int fromIndex, int toIndex)Sorts the specified range of the specified array of doubles into ascending numerical order.
static voidsort(float[] a)Sorts the specified array of floats into ascending numerical order.
static voidsort(float[] a, int fromIndex, int toIndex)Sorts the specified range of the specified array of floats into ascending numerical order.
static voidsort(int[] a)Sorts the specified array of ints into ascending numerical order.
static voidsort(int[] a, int fromIndex, int toIndex)Sorts the specified range of the specified array of ints into ascending numerical order.
static voidsort(long[] a)Sorts the specified array of longs into ascending numerical order.
static voidsort(long[] a, int fromIndex, int toIndex)Sorts the specified range of the specified array of longs into ascending numerical order.
static voidsort(Object[] a)Sorts the specified array of objects into ascending order, according to the natural ordering of its elements.
static voidsort(Object[] a, int fromIndex, int toIndex)Sorts the specified range of the specified array of objects into ascending order, according to the natural ordering of its elements.
static voidsort(short[] a)Sorts the specified array of shorts into ascending numerical order.
static voidsort(short[] a, int fromIndex, int toIndex)Sorts the specified range of the specified array of shorts into ascending numerical order.
static<T> void sort(T[] a, Comparator<? super T> c) Sorts the specified array of objects according to the order induced by the specified comparator.
static<T> void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c) Sorts the specified range of the specified array of objects according to the order induced by the specified comparator.

  import java.util.Arrays;

public class Main{
  public static void main(String args[]) {
    int array[] = new int[10];
    for (int i = 0; i < 10; i++){
      array[i] = -3 * i;
    }
    System.out.print("Original contents: ");
    System.out.println(Arrays.toString(array));
    Arrays.sort(array);
    System.out.print("Sorted: ");
    System.out.println(Arrays.toString(array));
  }
}
  

The output:


Original contents: [0, -3, -6, -9, -12, -15, -18, -21, -24, -27]
Sorted: [-27, -24, -21, -18, -15, -12, -9, -6, -3, 0]
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.