If you have a non primitive array type, you can use the following code to convert it to a list:

[java]

public class ArrayToListConverter { public static void main(String args[]){ Integer[] intArr = {2,4,6,8,10}; List intList = new ArrayList(); //Method 1 - Using for loop for(int i:intArr){ intList.add(i); }

//Method 2 - Via Arrays.asList intList = Arrays.asList(intArr);

//

}

[/java]

Method 1

Here, we are manually iterating through the elements in the list and adding them to an int array.

Method 2 

Here, we are using the Arrays.asList method. This returns a list corresponding to the array passed in. Note that this method wont work if the array is of primitive type like this:

[java]

int[] intArr = {2,4,6,8,10};

[/java]