I thought if it was possible to create a stream which has a custom increment, like one only containing multiples of a given number (2 in this example). Is there a way to make this work?
IntStream.iterate(2, num -> (int) Math.pow(2, num))
I thought if it was possible to create a stream which has a custom increment, like one only containing multiples of a given number (2 in this example). Is there a way to make this work?
IntStream.iterate(2, num -> (int) Math.pow(2, num))
 
    
    Multiples of a number? Shouldn't this work?
  IntStream.iterate(2, i -> i + 1)
            .filter(i -> i % 2 == 0)
            .limit(5)
            .forEach(System.out::println);
