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 {
    public static <E> Optional<E> min(List<E> elements, Comparator<E> comparator) {
        if (elements.size() != 0) {
            E minElement = elements.get(0);
            for (int i = 1; i < elements.size(); i++) {
                minElement = comparator.compare(minElement, elements.get(i)) < 0 ? minElement : elements.get(i);
            }
            return Optional.of(minElement);
        } else
            return Optional.empty();
    }
}