DoubleStream iterator() method in Java


The iterator() method of the DoubleStream class in Java returns an iterator for the elements of this stream.

The syntax is as follows

PrimitiveIterator.OfDouble iterator()

Here, PrimitiveIterator.OfDouble is an Iterator specialized for double values.

To use the DoubleStream class in Java, import the following package

import java.util.stream.DoubleStream;

The following is an example to implement DoubleStream iterator() method in Java

Example

 Live Demo

import java.util.*;
import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(50.6, 69.8, 81.8, 95.6, 106.9);
      PrimitiveIterator.OfDouble res = doubleStream.iterator();
      while (res.hasNext()) {
         System.out.println(res.nextDouble());
      }
   }
}

Output

50.6
69.8
81.8
95.6
106.9

Updated on: 30-Jul-2019

66 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements