Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Java-conversion Convert List to ArrayList

Related Tutorials


 
 

Share on Google+Share on Google+

Convert List to ArrayList

Advertisement
In this section, you will learn how to convert List to ArrayList.

Convert List to ArrayList

     

In this section, you will learn how to convert List to ArrayList. 

Code Description:

This program helps you in converting List to ArrayList.  Here we have taken a List of Colors or you can also take it as a queue as shown in the program. Then we have used a method i.e. "ListToArrList().convertFromQueueToList(); " to convert the list to ArrayList.

 

 

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class ListToArrList {
  public void convertFromQueueToList() {
  Queue colorsQueue = new LinkedList();
  colorsQueue.add("Mauve");
  colorsQueue.add("Peach");
  colorsQueue.add("Teal");
  colorsQueue.add("Rose");
  
  List colorsList = new ArrayList(colorsQueue);
  for (Object theColors : colorsList)
  System.out.println(theColors);
  }
  public static void main(String[] args) {
  new ListToArrList().convertFromQueueToList();
  }
}

Output of the program:

C:\unique>javac ListToArrList.java

C:\unique>java ListToArrList
Mauve
Peach
Teal
Rose

C:\unique>

Download this example:

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: December 13, 2008

Related Tutorials

Discuss: Convert List to ArrayList  

Post your Comment


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