Convert array to ArrayList in Java

December 23, 2016

You can convert arrays to ArrayList by using this method:

1. Convert Integer array to ArrayList

In the first line of above code, we declare an array of Integers. In the second line, we convert this array into ArrayList. Lastly, we print the integerList.

The output of the above program is:

2. Convert String array to ArrayList

When it comes to Strings the things are very similar. You can see it in this example:

The output of the above program is:

3. Convert primitive type array to ArrayList

Next, we will consider arrays which have primitive types.

In this example conversion is simple. At the beginning we declare intArray. Nextly, we declare a new integerLit. After that we copy each element of intArray into integerList. The output of execution of this program is:

Click here to add a comment

Leave a comment: