Example usage for java.util Arrays sort

List of usage examples for java.util Arrays sort

Introduction

In this page you can find the example usage for java.util Arrays sort.

Prototype

public static <T> void sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c) 

Source Link

Document

Sorts the specified range of the specified array of objects according to the order induced by the specified comparator.

Usage

From source file:Main.java

public static void main(String[] args) {

    // initializing unsorted short array
    Short sArr[] = new Short[] { 3, 13, 1, 9, 21 };

    System.out.println(Arrays.toString(sArr));

    // create a comparator
    Comparator<Short> comp = Collections.reverseOrder();

    // sorting array with reverse order using comparator from 0 to 2
    Arrays.sort(sArr, 0, 2, comp);

    System.out.println(Arrays.toString(sArr));
}