|
Arrays Sort
The following example shows how to sort any given array using Arrays.sort() API.
|
package com.bethecoder.tutorials.utils.arrays;
import java.util.Arrays;
public class ArraysSort {
public static void main (String [] args) {
int [] intArray = { 7, 8, 6, 1, 4, 2, 9};
System.out.println("Before sort : " + Arrays.toString(intArray));
Arrays.sort(intArray);
System.out.println("After sort : " + Arrays.toString(intArray));
System.out.println();
char [] chrArray = { 'b', 'e', 't', 'c', 'o', 'd', 'e', 'r' };
System.out.println("Before sort : " + Arrays.toString(chrArray));
Arrays.sort(chrArray);
System.out.println("After sort : " + Arrays.toString(chrArray));
}
}
|
| |
It gives the following output,
Before sort : [7, 8, 6, 1, 4, 2, 9]
After sort : [1, 2, 4, 6, 7, 8, 9]
Before sort : [b, e, t, c, o, d, e, r]
After sort : [b, c, d, e, e, o, r, t]
|
|