import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Stream {
//流的理解,把它定义成遍历数据集合的高级迭代器。还有并行流的高级写法
public static void main(String[] args) {
List<Shop> shops = new ArrayList<Shop>();
shops.add(new Shop("Kobe"));
shops.add(new Shop("KKone"));
shops.add(new Shop("Wade"));
List<String> ll = shops.stream().map(Shop::getName).limit(2).filter(shop->{
return shop.startsWith("K");
}).collect(Collectors.toList());
System.out.println(ll);
}
}
输出结果:
[Kobe, KKone]