Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert List of Array into single Array

Tags:

java

arrays

list

How to convert List of arrays into a single array in Java. Is there any predefined function to use?

Below is the list of arrays, I want to iterate and keep all values in a single array.

List<Integer[]> integerArrayList = new ArrayList<Integer[]>();

Integer[] resultArray = {};

Is there efficient way to implement?

like image 444
Mohankumar Rathinam Avatar asked Oct 29 '25 19:10

Mohankumar Rathinam


1 Answers

Java 8's stream make this pretty easy:

Integer[] resultArray = 
    integerArrayList.stream().flatMap(Arrays::stream).toArray(Integer[]::new);
like image 115
Mureinik Avatar answered Nov 01 '25 10:11

Mureinik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!