Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Main {
    public static void main(String[] args) {

        List<String> friends = Arrays.asList("CSS", "HTML", "Oracle", "Dart");
        Comparator<String> compByLength = (aName, bName) -> aName.length() - bName.length();
        friends.stream().max(compByLength)
                .ifPresent(longest -> System.out.println("\nThe longest name is " + longest));
    }
}