Java Streams - LongStream iterator() example








LongStream iterator() returns iterator for LongStream.

Syntax

iterator has the following syntax.

PrimitiveIterator.OfLong iterator()

Example

The following example shows how to use iterator.

import java.util.PrimitiveIterator;
import java.util.stream.LongStream;
/*from w w w . j  av a2s  . c  om*/
public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.empty();
    PrimitiveIterator.OfLong o = b.iterator();
    while(o.hasNext()){
      System.out.println(o.next());  
    }    
  }
}