进阶day07-Stream流中的常用方法_limit(截取)
This commit is contained in:
14
javaSE-day07/src/com/inmind/stream03/LimitDemo21.java
Normal file
14
javaSE-day07/src/com/inmind/stream03/LimitDemo21.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.inmind.stream03;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Stream流中的常用方法_limit
|
||||||
|
将指定的流的前几个元素,组成一个新的流返回
|
||||||
|
*/
|
||||||
|
public class LimitDemo21 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Stream<Integer> stream = Stream.of(1, 2, 3, 4, 5, 6);
|
||||||
|
stream.limit(3).forEach(i-> System.out.println(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user