Computer Science, asked by sreevani7917, 1 year ago

How to switch data from an array to array list in java?

Answers

Answered by megha0754
0

Answer:

the array class of the java.util package provides you a method named as list().this method accepts an array(of objects) and converts them into a list and returns it.

Attachments:
Answered by Oreki
0

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