In this section, you will learn about converting Array into ArrayList.
Array is a data structure having fixed size which stores same type of elements in sequential manner. While ArrayList ,extends AbstractList and implements the List interface , supports dynamic array which can grow in size .
Situation comes when you have data in Array and you want to convert it into ArrayList. This can be done using asList() method as follows :
import java.util.*;
public class ConvertArrayToArrayList {
public static void main(String args[]) {
String[] states= {"UP", "Bihar", "Kolkata", "Delhi"};
List stateslist = new Arrays(Arrays.asList(states));
System.out.println("ArrayList of states: " + stateslist);
}
}
OUTPUT :
ArrayList of states: [UP, Bihar, Kolkata, Delhi]
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Convert Array to ArrayList
Post your Comment