Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        String[] array = { "Java", "C#", "Scala", "Basic", "C++", "Ruby", "Pyton", "Perl", "Haskell", "Jet" };
        System.out.println("Shortest to longest: ");
        Arrays.sort(array, (s1, s2) -> s1.length() - s2.length());
        Arrays.asList(array).forEach(System.out::println);

        System.out.println("\nLongest to shortest: ");
        Arrays.sort(array, (s1, s2) -> (s2.length() - s1.length()));
        Arrays.asList(array).forEach(System.out::println);

        System.out.println("\nAlphabetically by the first character only: ");
        Arrays.sort(array, (s1, s2) -> s1.charAt(0) - s2.charAt(0));
        Arrays.asList(array).forEach(System.out::println);
    }
}