The Future Is Behind You

Reverse Sort an Array

Fill an array with letters and then sort it by reverse order.

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

public class ReverseOrder {

  public static void main(String[] args) {
    String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i"};
    Arrays.sort(letters, Collections.reverseOrder());

    for (String s : letters) {
      System.out.println(s);
    }
  }
}

Output:

i
h
g
f
e
d
c
b
a

Source Code

a = b = c