Common methods in Stream _skip

Skip the first few: skip:
Common methods in the Stream stream _skip: used to skip elements
If you want to skip the first few elements, you can use the skip method to get a new stream after interception

 Stream<T> skip(long n);
    如果流的当前长度大于n,则跳过前n个;否则将会得到一个长度为0的空流

Example:

public class Demo07Stream_skip {
    
    
    public static void main(String[] args) {
    
    
        //获取一个Stream流
        String[] arr = {
    
    "喜羊羊","美羊羊","灰太狼","懒羊羊","红太狼"};
        Stream<String> stream = Stream.of(arr);
        //使用skip方法跳过前3个元素
        Stream<String> stream2 = stream.skip(3);
        //遍历stream2流
        stream2.forEach(name-> System.out.println(name));
    }
}

Program demonstration:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44664432/article/details/109156320