Java 8ストリーム処理
1094 ワード
レコードJava 8ストリーム処理
/*
*author:cst
*
*/
FlatMap()
Stream.flatMap(Function super String, ? extends Stream extends String>> mapper)
api:
Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Each mapped stream is closed after its contents have been placed into this stream. (If a mapped stream is null an empty stream is used, instead.)
, 。 。( null, )
:
List list = Arrays.asList(3,5,6,9,23,69,6,3,8,63);
Stream s = list.stream().flatMap(e->filteInteger(e));
s.forEach(e->System.out.println(e));
private static Stream filteInteger(Integer i)
{
List l = new LinkedList();
if(i.intValue()>10)
{
l.add(1);l.add(2);
}
return l.stream();
}
//
1
2
1
2
1
2