Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

public class Main {
    /**
     * @return the last element in the list, or empty if the list is empty
     */
    public static <E> Optional<E> last(List<E> list) {
        if (list.isEmpty())
            return Optional.empty();
        return Optional.of(list.get(list.size() - 1));
    }
}