Java Stream skip elements

Description

Java Stream skip elements


import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    Stream.iterate(2L, n  ->  n  + 1)
    .filter(Main::isOdd)/*ww  w.  j a  va2  s. com*/
    .skip(10)
    .limit(10)
    .forEach(System.out::println);
  }
  public static boolean isOdd(long number) {
    if (number % 2 == 0) {
      return false;
    }
    return true;
  }
}



PreviousNext

Related