package org.coffeedriven; | |
import java.math.BigDecimal; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class StreamExample2 { | |
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"))); | |
List<String> names = items.stream() | |
.map(item -> item.getName()) | |
.filter(name -> name.endsWith("C")) | |
.collect(Collectors.toList()); | |
System.out.println("Names with C : " + names); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment