Java Arrays sort an array in reversed order

Description

Java Arrays sort an array in reversed order

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

public class Main {

  public static void main(String[] args) {
    Integer[] intArray = { 431, 1235, 931, 1230, 5433, 5345, 65345, 2543 };

    System.out.println(Arrays.toString(intArray));
    Arrays.sort(intArray);/*w w  w.j av  a 2s.co  m*/
    System.out.println(Arrays.toString(intArray));

    Arrays.sort(intArray,Collections.reverseOrder());
    System.out.println(Arrays.toString(intArray));

    String[] stringArray = { "Java", "CSS", "HTML", "Javascript", "SQL" };

    System.out.println(Arrays.toString(stringArray));
    Arrays.sort(stringArray);
    System.out.println(Arrays.toString(stringArray));

    Arrays.sort(stringArray,Collections.reverseOrder());
    System.out.println(Arrays.toString(stringArray));

  }
}



PreviousNext

Related