Home Java Beginners Arrayexamples Convert Array to ArrayList
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Convert Array to ArrayList

Advertisement
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]

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 4, 2013

Related Tutorials

Ask Questions?    Discuss: Convert Array to ArrayList  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com