Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class Main {

    public static void main(String[] args) {
        List<String> names = Arrays.asList("XML", "HTML", "CSS", "Javascript", "Java", "Static");

        Optional<String> longestName = names.stream()
                .reduce((name1, name2) -> name1.length() >= name2.length() ? name1 : name2);

        if (longestName.isPresent()) {
            System.out.println(longestName.get());
        } else {
            System.out.println("WTF?");
        }

    }
}