Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package org.coffeedriven;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class StreamExample {
public static void main(String[] args) {
List<Item> items = new ArrayList<Item>();
items.add(new Item("itemA", 1, new BigDecimal("1.0")));
items.add(new Item("itemB", 2, new BigDecimal("2.0")));
items.add(new Item("itemC", 3, new BigDecimal("3.0")));
long count =
.map(item -> item.getName()) // extract name from item
.filter(name -> name.endsWith("C")) // filter items for which name ends with "C"
System.out.println("Count is : " + count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment