Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.*;

public class Main {
    static <E> Optional<E> max(List<E> elements, Comparator<E> comparator) {
        //TODO Implement me
        E maxValue = elements.get(0);
        int i = 0;
        while (i <= elements.size()) {
            maxValue = comparator.compare(maxValue, elements.get(i)) > 0 ? maxValue : elements.get(i);
            i++;
        }
        return Optional.of(maxValue);
    }
}