java的stream流skip函数
时间: 2023-10-15 19:25:04 浏览: 153
Java Stream 流的使用过程解析
在Java的Stream流中,skip函数用于跳过流中的前n个元素,并返回一个新的流。如果流的当前长度大于n,则跳过前n个元素,否则返回一个长度为0的空流。下面是一个示例代码:
```java
Stream<String> stream = Stream.of("张老三", "张小三", "李四", "赵五", "刘六", "王七");
stream.skip(3).forEach((String name) -> {
System.out.println("跳过前三个,打印剩下的" + name);
});
```
运行以上代码会输出以下结果:
跳过前三个,打印剩下的赵五
跳过前三个,打印剩下的刘六
跳过前三个,打印剩下的王七<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Java Stream流(详解)](https://blog.csdn.net/m0_60489526/article/details/119984236)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文