HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaCritical

Create ArrayList from array

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
arrayfromarraylistcreate

Problem

Element[] array = {new Element(1), new Element(2), new Element(3)};


How do I convert the above variable of type Element[] into a variable of type ArrayList?
ArrayList arrayList = ...;

Solution

You can use the following instruction:

new ArrayList<>(Arrays.asList(array));

Code Snippets

new ArrayList<>(Arrays.asList(array));

Context

Stack Overflow Q#157944, score: 5154

Revisions (0)

No revisions yet.