Java Set to Array

Previous
Next

In this post, we will learn java set to array conversion.


There are many ways to convert set to an array.


1. Using Java 8’s Stream

If you are using Java 8, I would recommend using this method.

Output

[John, Martin, Mary]

2. Using toArray()

We can directly call toArray method on set object for java set to array conversion.

Output

[John, Martin, Mary]

3. Using System.arraycopy()

We can use System.arraycopy for java set to List conversion.

Output

[John, Martin, Mary]

4. Using simple iteration

Iterate through set and put the value in array manually.

Output

[John, Martin, Mary]

Previous
Next

Join Our News Letter – Stay Updated

Subscribe to Awesome Java Content.




Add Comment

Join Our News Letter - Stay Updated

Subscribe to Awesome Java Content.
You can like our facebook page Java2blog