Java Stream create with custom generator method

Description

Java Stream create with custom generator method

import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) {
    Stream.generate(new My()::next)
    .skip(100)/* w w w.  j  a v  a 2  s. c  o m*/
    .limit(5)
    .forEach(System.out::println);
  }
}

class My {
  private long a = 0L;

  public long next() {
    return a++;
  }

}



PreviousNext

Related