Sort an array

static void sort(byte[] a)
Sorts the specified array of bytes into ascending numerical order.
static void sort(byte[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of bytes into ascending numerical order.
static void sort(char[] a)
Sorts the specified array of chars into ascending numerical order.
static void sort(char[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of chars into ascending numerical order.
static void sort(double[] a)
Sorts the specified array of doubles into ascending numerical order.
static void sort(double[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of doubles into ascending numerical order.
static void sort(float[] a)
Sorts the specified array of floats into ascending numerical order.
static void sort(float[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of floats into ascending numerical order.
static void sort(int[] a)
Sorts the specified array of ints into ascending numerical order.
static void sort(int[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of ints into ascending numerical order.
static void sort(long[] a)
Sorts the specified array of longs into ascending numerical order.
static void sort(long[] a, int fromIndex, int toIndex)
Sorts the specified range of the specified array of longs into ascending numerical order.
static void sort(Object[] a)
Sorts the specified array of objects into ascending order, according to the natural ordering of its elements.
static void sort(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 void sort(short[] a)
Sorts the specified array of shorts into ascending numerical order.
static void sort(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]
Home 
  Java Book 
    Collection  

Arrays:
  1. Arrays
  2. Convert array to list
  3. Binary search an Array
  4. Deep to string
  5. Compare two arrays
  6. Fill value to array
  7. Sort an array
  8. Convert array to string