Home Java Beginners Arrayexamples Convert Array to ArrayList



Convert Array to ArrayList
Posted on: February 4, 2013 at 12:00 AM
In this section, you will learn about converting Array into 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]

Related Tags for Convert Array to ArrayList:


More Tutorials from this section

Ask Questions?    Discuss: Convert Array to ArrayList  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

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.