Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

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

public class Main {
    /**
     * @return transform the element into an arraylist containing the element, or an empty ArrayList if the element is empty
     */
    @SafeVarargs
    public static <E> List<E> asArrayList(Optional<E>... elements) {
        List<E> newArrayList = new ArrayList<>();
        for (Optional<E> element : elements) {
            element.ifPresent(newArrayList::add);
        }
        return newArrayList;
    }
}