Sort char Array in Java
Description
The following code shows how to sort char Array.
Example
//from ww w.j a v a 2 s . c o m
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
char[] c1 = new char[] { 'c', 'h', 'a', 'r', 's' };
System.out.print(Arrays.toString(c1));
Arrays.sort(c1);
System.out.print(Arrays.toString(c1));
char[] c2 = new char[] { 'c', 'h', 'a', 'r', 's' };
Arrays.sort(c2, 1, 4);
System.out.print(Arrays.toString(c2));
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »