Convert Array to ArrayList

In this section, you will learn about converting Array into ArrayList.

Convert Array to ArrayList

Convert Array to ArrayList

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]