Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
communitycreator

What is the toArray() method of the DoubleStream interface?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The DoubleStream interface’s toArray() method creates an array of the double type. This array consists of the stream’s elements. This method is a terminal/last operation in the stream pipeline.

Syntax

double[] toArray();

Parameters

The method has no parameters.

Return value

The method returns an array of the double type.

Code

import java.util.Arrays;
import java.util.stream.DoubleStream;
class Main {
public static void main(String[] args) {
DoubleStream doubleStream = DoubleStream.of(5.6, 10.9, 12.4, 34.2, 0.00032);
double[] doubleArray = doubleStream.toArray();
System.out.println("Converting the DoubleStream to an array - " + Arrays.toString(doubleArray));
}
}
Implementation of the toArray method

Explanation

  • Lines 1 and 2: We import the Arrays class and the DoubleStream interface.
  • Line 6: We create a stream of double values.
  • Line 7: We convert the stream to a double type array using the toArray() method.
  • Line 8: We print the double type array.

RELATED TAGS

java
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring