Java Stream filter odd value

Description

Java Stream filter odd value

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 2  s  .co m
    .limit(20)
    .forEach(System.out::println);
  }
  public static boolean isOdd(long number) {
    if (number % 2 == 0) {
      return false;
    }
    return true;
  }
}



PreviousNext

Related