Array sort
In this chapter you will learn:
Sort an array
The following methods sort the specified array into ascending numerical order.
static void sort(byte[] a)
static void sort(byte[] a, int fromIndex, int toIndex)
static void sort(char[] a)
static void sort(char[] a, int fromIndex, int toIndex)
static void sort(double[] a)
static void sort(double[] a, int fromIndex, int toIndex)
static void sort(float[] a)
static void sort(float[] a, int fromIndex, int toIndex)
static void sort(int[] a)
static void sort(int[] a, int fromIndex, int toIndex)
static void sort(long[] a)
static void sort(long[] a, int fromIndex, int toIndex)
static void sort(Object[] a)
static void sort(Object[] a, int fromIndex, int toIndex)
static void sort(short[] a)
static void sort(short[] a, int fromIndex, int toIndex)
static<T> void sort(T[] a, Comparator<? super T> c)
static<T> void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)
import java.util.Arrays;
/*from ja va 2 s . c o m*/
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:
Next chapter...
What you will learn in the next chapter:
Home » Java Tutorial » Data Types