Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        // Sort the names based on their length, placing null first
        SortedSet<String> names = new TreeSet<>(Comparator.nullsFirst(Comparator.comparing(String::length)));
        names.add("XML");
        names.add("CSS");
        names.add("HTML");
        names.add(null); // Adds a null

        // Print the names
        names.forEach(System.out::println);

    }

}