How to create an ArrayList from an Array in Java?
Answers
Answered by
0
I do not know. It is just written by
int a[]=new int[10];
Answered by
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
History,
6 months ago
Environmental Sciences,
6 months ago
Biology,
1 year ago
Chemistry,
1 year ago
Chemistry,
1 year ago