s-day07--Stream流中的常用方法_limit
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.inmind.stream03;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/*
|
||||
26.Stream流中的常用方法_limit
|
||||
Stream<T> limit(long maxSize) 返回由此流的元素组成的流,截短长度不能超过 maxSize 。
|
||||
将制定的流的前几个元素,组成一个新的流
|
||||
*/
|
||||
public class LimitDemo13 {
|
||||
public static void main(String[] args) {
|
||||
Stream<Integer> stream = Stream.of(1, 2, 3, 4, 5);
|
||||
//我想将1,2,3,作为元素,组成新的流
|
||||
Stream<Integer> newStream = stream.limit(3);
|
||||
//System.out.println(newStream.count());
|
||||
newStream.forEach(i-> System.out.println(i));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user