All Downloads are FREE. Search and download functionalities are using the official Maven repository.

examples.Lambda Maven / Gradle / Ivy

import java.util.*;
import java.util.stream.*;

public class Lambda
{
    public static void main(String[] args)
    {
        List items = new ArrayList<>();

        items.add("apple");
        items.add("banana");
        items.add("blueberry");
        items.add("cherry");
        items.add("pineapple");
        items.add("pear");
        items.add("strawberry");

        List filtered = items.stream().filter( item -> item.startsWith("b") ).collect(Collectors.toList());

        for (Object str : filtered)
        {
            System.out.println(str);
        }
    }
}