Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {

    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
        Arrays.sort(sArr, comp);

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