Converting java arrays into list

Learn How java arrays is converted into list.


Share on Google+Share on Google+

Converting java arrays into list


Learn How java arrays is converted into list.

In this tutorial we are going to create array object and then convert it into the list object. Java Array provides a method asList() which is used to convert an array object into the list object.

When you call the  asList() method on the object of array, it will create an instance of the list with the data from the array and returned into variable. You can assign this list object into a variable and use in your program.

In this program we are just printing the size of the list.

  • Arrays can be converted by the asList() method of the Arrays class.
  • asList() It converts the object array into the fixed sized list

Example Code:

Code for converting array into list is:


Following is the complete code which is using the method asList() to convert array into list object.

import java.util.*;
public class array4 {

public static void main(String[] args) {
        String ar[]={"aaa","bbb","ccc","ddd"};
        Integer  ar1[]={111,222,333,444};
        List list=new ArrayList();
        List list1=new ArrayList();


[aaa, bbb, ccc, ddd]
[111, 222, 333, 444]

If you run the program it will display above output.

In this tutorial we have explained you the code for converting an array into list object. Following are more tutorials of arrays in Java:



Posted on: October 22, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles