Create a gist now

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 = items.stream()
.map(item -> item.getName()) // extract name from item
.filter(name -> name.endsWith("C")) // filter items for which name ends with "C"
.count();
System.out.println("Count is : " + count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment