Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static void main(String[] argv) throws Exception {

        int[] intArray = new int[] { 4, 1, 3, -23 };
        Arrays.sort(intArray);
        // [-23, 1, 3, 4]

        String[] strArray = new String[] { "z", "a", "C" };
        Arrays.sort(strArray);
        // [C, a, z]

        // Case-insensitive sort
        Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER);
        // [a, C, z]

        // Reverse-order sort
        Arrays.sort(strArray, Collections.reverseOrder());
        // [z, a, C]

        // Case-insensitive reverse-order sort
        Arrays.sort(strArray, String.CASE_INSENSITIVE_ORDER);
        Collections.reverse(Arrays.asList(strArray));
        // [z, C, a]
    }
}