Computer Science, asked by ansul3465, 1 year ago

How to create an ArrayList from an Array in Java?

Answers

Answered by amannishad0512p5zxh6
0

I do not know. It is just written by

int a[]=new int[10];

Answered by Oreki
1

We can convert an Array into an ArrayList in Java using a class from java.util package called Arrays.

We can import this class and convert our Array to an ArrayList.

For example -

Given, an Array,

   String[ ] myArray = {"One", "Two", "Three", "Four", "Five"};

For converting,

   ArrayList<String> myArrayList = new ArrayList<>(Arrays.asList(myArray)); or,

   var myArrayList = new ArrayList<>(Arrays.asList(myArray));

Similar questions