Languages
[Edit]
EN

Java - convert List<Double> to double[] - boxed Double list to array of primitive doubles

13 points
Created by:
Efe-V
409

1. Overview

Edit

In this post we cover how to convert List<Double> to double[] in couple of different ways.

Simplest way to do it:

2. Using Java 8 - Stream.mapToDouble example 1

Edit

Stream.mapToDouble with method reference.

Output:

3. Using Java 8 - Stream.mapToDouble example 2

Edit

Stream.mapToDouble with identity function

Output:

4. Before java 8 - using explicit iteration over list

Edit

Output:

5. Using Guava

Edit

Output:

Maven dependency - Guava version 28.0 

6. Using Apache commons lang3 

Edit

Output:

Maven dependency - Apache commons lang3 version 3.8.1

Merged questions

Edit
  1. Java - how to cast List<Double> to double[]
  2. Java - how to convert List<Double> to array of primitive double values
  3. How to convert List of Double objects to array of primitive doubles

Reference

Edit
  1. Stream.mapToDouble - Java 8 docs
  2. Doubles.toArray - Guava docs
  3. ArrayUtils.toPrimitive - Apache commons lang3 docs
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java conversion

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join