Java Stream create from iterator

Description

Java Stream create from iterator


import java.util.stream.Stream;

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



PreviousNext

Related