Arrays: sort(T[] a, Comparator c) : Arrays « java.util « Java by API






Arrays: sort(T[] a, Comparator c)

   
/*
 Output:

c
b
a


 * */

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class MainClass {
  public static void main(String args[]) throws Exception {
    Comparator comp = Collections.reverseOrder();
    String[] a = new String[] { "a", "b", "c" };
    Arrays.sort(a, comp);
    for (int i = 0, n = a.length; i < n; i++) {
      System.out.println(a[i]);
    }
  }
}
           
         
    
    
  








Related examples in the same category

1.Arrays: asList(T[] a)
2.Arrays: binarySearch(int[] a,int key)
3.Arrays: binarySearch(Object[] a, Object key)
4.Arrays: copyOf(String[] original, int newLength)
5.Arrays: copyOfRange(String[] original, int from, int to)
6.Arrays: deepToString(Object[] a)
7.Arrays: equals(boolean[] a, boolean[] a2)
8.Arrays: equals(char[] a, char[] a2)
9.Arrays: equals(double[] a, double[] a2)
10.Arrays: equals(float[] a, float[] a2)
11.Arrays: equals(int[] a, int[] a2)
12.Arrays: equals(long[] a, long[] a2)
13.Arrays: equals(Object[] a, Object[] a2)
14.Arrays: equals(short[] a, short[] a2)
15.Arrays: fill(boolean[] a, boolean val)
16.Arrays: fill(boolean[] a, int fromIndex, int toIndex, boolean val)
17.Arrays: fill(byte[] a, byte val)
18.Arrays: fill(byte[] a, int fromIndex, int toIndex, byte val)
19.Arrays: fill(char[] a, char val)
20.Arrays: fill(char[] a, int fromIndex, int toIndex, char val)
21.Arrays: fill(double[] a, double val)
22.Arrays: fill(double[] a, int fromIndex, int toIndex, double val)
23.Arrays: fill(float[] a, float val)
24.Arrays: fill(float[] a, int fromIndex, int toIndex, float val)
25.Arrays: fill(int[] a, int val)
26.Arrays: fill(long[] a, long val)
27.Arrays: fill(long[] a, int fromIndex, int toIndex, long val)
28.Arrays: fill(Object[] a, Object val)
29.Arrays: fill(int[] a,int fromIndex,int toIndex,int val)
30.Arrays: fill(Object[] a, int fromIndex, int toIndex, Object val)
31.Arrays: fill(short[] a, short val)
32.Arrays: fill(short[] a, int fromIndex, int toIndex, short val)
33.Arrays: sort(byte[] a)
34.Arrays: sort(byte[] a, int fromIndex, int toIndex)
35.Arrays: sort(char[] a)
36.Arrays: sort(char[] a, int fromIndex, int toIndex)
37.Arrays: sort(double[] a)
38.Arrays: sort(double[] a, int fromIndex, int toIndex)
39.Arrays: sort(float[] a)
40.Arrays: sort(float[] a, int fromIndex, int toIndex)
41.Arrays: sort(in[] a)
42.Arrays: toString(Object[] a)