Home » Java » Duplicate every element of array via streams in Java

Duplicate every element of array via streams in Java

Posted by: admin June 14, 2018 Leave a comment

Questions:

I have some array

int[] a = {1,2,3,4,5};

How can I get another array from this with duplicate elements via streams.
I mean something like this

result = Stream.of(a).map(...)
// after that result = {1,1,2,2,3,3,4,4,5,5}
Answers: