描述:
Stream传入一组数字然后处理得到其他类型的输出
等效以下代码:
//method
List<Foo> fooList = new ArrayList<>();
for (Integer i: Arrays.asList(1, 2, 3)) {
fooList.add(new Foo(i, i.toString()));
}
return fooList;
//method
//Foo类
class Foo(int i, String s){}
搜了下没找到类似这种的,一般都是输入输出一致那种.
问题解决了
使用Stream.map(Function<T, R>)来处理.
integer是输入, new Foo(integer, integer.toString())是输出.