First of all, for initializing a container you cannot use a primitive type (i.e. int; you can use int[] but as you want just an array of integers, I see no use in that). Instead, you should use Integer, as follows:

ArrayList<Integer> arl = new ArrayList<Integer>();

For adding elements, just use the add function:

arl.add(1);  
arl.add(22);
arl.add(-2);

Last, but not least, for printing the ArrayList you may use the build-in functionality of toString():

System.out.println("Arraylist contains: " + arl.toString());  

If you want to access the i element, where i is an index from 0 to the length of the array-1, you can do a :

int i = 0; // Index 0 is of the first element
System.out.println("The first element is: " + arl.get(i));

I suggest reading first on Java Containers, before starting to work with them.

Answer from Raul Rene on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-in-java
ArrayList in Java - GeeksforGeeks
Explanation: This program creates an ArrayList of integers, adds elements to it using the add() method, and stores them dynamically.
Published: May 12, 2026
Discussions

arrays - Java ArrayList for integers - Stack Overflow
I have values that I'd like to add into an ArrayList to keep track of what numbers have shown up. The values are integers so I created an ArrayList; ArrayList list = new ArrayList... More on stackoverflow.com
🌐 stackoverflow.com
What's the difference between new ArrayList<Integer>() and new ArrayList();
if you don't include the generic type then it's a "raw" type, which is bad, don't do that, it will turn off type checking for elements (note: raw new ArrayList() should not be confused with new ArrayList<>() which is perfectly fine and it just a way of saving typing called diamond) BTW the conventional way is like this: List arr = new ArrayList<>(); Use just the interface name on the left, and use diamond on the right More on reddit.com
🌐 r/learnjava
17
36
November 15, 2022
How do I make integer lists in Java?
Java has arrays, like int[], but they are not dynamically resizable, and there are some other idiosyncracies as well. Instead prefer to use the generic List interface. Most often, you will want to specifically use the ArrayList implementation, as this gives you O(1) random access and is the Java equivalent to a Python list. Java generics have the caveat that you can't use them with primitive types like int, so instead you should use a wrapper class like Integer. tl;dr: List More on reddit.com
🌐 r/learnprogramming
4
0
February 4, 2019
How to create ArrayList (ArrayList<Integer>) from array (int[]) in Java - Stack Overflow
Releases Keep up-to-date on features ... Stack Internal. ... The 2026 Annual Developer Survey Results Site is live— view the results here! Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... import java.util.ArrayList; import ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
It is part of the java.util package and implements the List interface. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you want to add or remove elements to/from an array, you have to create a new one).
🌐
Dot Net Perls
dotnetperls.com › arraylist-integer-java
Java - ArrayList int, Integer Examples - Dot Net Perls
We cannot specify int as the type of an ArrayList. An int is not a "ReferenceType". Instead we must use Integer—and add only Integers to this collection. import java.util.ArrayList; public class Program { public static void main(String[] args) { // This does not compile.
Find elsewhere
🌐
Reddit
reddit.com › r/learnjava › what's the difference between new arraylist() and new arraylist();
r/learnjava on Reddit: What's the difference between new ArrayList<Integer>() and new ArrayList();
November 15, 2022 -

The difference between the datatype and the constructor was confusing to me, so I did some tests.

ArrayList<Integer> arr = new ArrayList<Integer>();
arr.add(0);

in this example "arr.get(0)", will give us an Integer (as intended)

ArrayList arr = new ArrayList<Integer>();
arr.add(0);

In this one it will give us an Object so we need to cast it.

ArrayList<Integer> arr = new ArrayList();
arr.add(0);

In this one it will also give us an Integer (*like the first one*)

So my question is, what's the difference between the first and last one? why would I write ArrayList<Integer>()? if only ArrayList(); will do the work?

🌐
Coderanch
coderanch.com › t › 464780 › java › ArrayList-Integer
new ArrayList<Integer>({1,2,3,4}) (Beginning Java forum at Coderanch)
October 1, 2009 - To make it work, you can convert array declaration from int (primitive type) to object type Integer. ... Moreover I don't understand why you need to wrap the created list through Arrays util class again in ArrayList, when Arrays.asList() returns a list and that can be assigned to reference variable directly.
🌐
Reddit
reddit.com › r/learnprogramming › how do i make integer lists in java?
r/learnprogramming on Reddit: How do I make integer lists in Java?
February 4, 2019 -

It seems a lot easier from the very little time I spent on Python before making the jump to Java. I'm taking a college night class on Java, and lists are one thing that are confusing me. How do they work in Java?

🌐
GeeksforGeeks
geeksforgeeks.org › java › convert-an-arraylist-containing-integers-to-primitive-int-array-in-java
How to Convert an ArrayList Containing Integers to Primitive Int Array? - GeeksforGeeks
July 23, 2025 - In Java, ArrayList is the pre-defined class of the Java Collection Framework. It is part of the java.util package. ArrayList can be used to add or remove an element dynamically in the Java program. It can be snipped dynamically based on the elements added or removed into the ArrayList.
🌐
YouTube
youtube.com › shukri abo tteen
How To Create An ArrayList of Integers | ArrayList in Java Tutorial - YouTube
In this video we will look at how to create an arraylist of primitive data types such as integers and doubles.
Published: January 22, 2021
Views: 5K
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-of-arraylist-in-java
ArrayList of ArrayList in Java - GeeksforGeeks
July 11, 2025 - // Java code to demonstrate the concept of // array of ArrayList import java.util.*; public class Arraylist { public static void main(String[] args) { int n = 3; // Here aList is an ArrayList of ArrayLists ArrayList<ArrayList<Integer> > aList ...
🌐
Quora
quora.com › How-do-I-convert-an-array-list-to-Integer-in-Java
How to convert an array list to ‘Integer’ in Java - Quora
Answer (1 of 5): Use the Integer.parseInt () method. ArrayList strArrayList = new ArrayList ();. // Declare a new list of string strArrayList.add(“1”); //add string 1 inside strArrayList.add(“2”); //add string 2 inside int[] ArrayY = new int[strArrayList.size()]; //declare a ne...
🌐
DEV Community
dev.to › pfilaretov42 › tiny-how-the-conversion-of-int-to-list-can-be-buggy-21oa
[Tiny] How the conversion of int[] to List<Integer> can be buggy? - DEV Community
June 1, 2023 - Okay, so let's fix the first one by adding diamond operator <> to new ArrayList: int[] array = new int[]{42, 5, 1, 3, 4}; List<Integer> list = new ArrayList<>(Arrays.asList(array)); System.out.println(list.get(0));
🌐
GeeksforGeeks
geeksforgeeks.org › java › array-of-arraylist-in-java
Array of ArrayList in Java - GeeksforGeeks
July 11, 2025 - // Java code to demonstrate the concept of // array of ArrayList import java.util.*; public class Arraylist { public static void main(String[] args) { int n = 5; // Here al is an array of arraylist having // n number of rows.The number of columns ...
🌐
Ducmanhphan
ducmanhphan.github.io › 2022-04-17-how-to-convert-int-to-list-integer
How to convert int[] to List of Integer
int[] rawData = {1, 3, 5}; List<Integer> data = new ArrayList<Integer>(); Arrays.stream(rawData).forEach(data::add); To reduce this version, we can use IntStream.of() method. int[] rawData = {1, 3, 5}; List<Integer> data = IntStream.of(rawData) ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
July 21, 2026 - Java™ Platform Standard Ed. 8 ... public class ArrayList<E> extends AbstractList<E> implements List<E>, RandomAccess, Cloneable, Serializable · Resizable-array implementation of the List interface. Implements all optional list operations, and permits all elements, including null.
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-size-method-in-java-with-examples
ArrayList size() Method in Java with Examples - GeeksforGeeks
July 28, 2026 - It is commonly used to determine the length of an ArrayList, validate indices, control loops, or check whether the list contains any elements. Does not include unused internal capacity. Returns an int value. Executes in constant time.