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
🌐
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).
🌐
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?

🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
April 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.
Find elsewhere
🌐
CodeHS
codehs.com › tutorial › 13901
Tutorial: ArrayLists in Java | CodeHS
Learn how to create and use ArrayLists in your programs!
🌐
Coderanch
coderanch.com › t › 464780 › java › ArrayList-Integer
new ArrayList<Integer>({1,2,3,4}) (Beginning Java forum at Coderanch)
October 1, 2009 - programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums · this forum made possible by our volunteer staff, including ... ... Hello, How can I add some values in a List while I instantiate it? Something like: List<Integer> a = new ArrayList<Integer>({1,2,3,4}); I do not want to use: a.add(1); a.add(2); ..
🌐
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 - Here is the sample: int[] array = new int[]{42, 5, 1, 3, 4}; List<Integer> list = new ArrayList(Arrays.asList(array)); System.out.println(list.get(0)); What do you think will be printed?
🌐
Lawrence
www2.lawrence.edu › fast › GREGGJ › CMSC150 › 062ArrayLists › ArrayLists.html
Working with ArrayLists
ArrayList<int> C = new ArrayList<int>(); // Illegal - int is not an object type · The workaround for this is that Java provides a class equivalent for every one of the primitive types. For example, there is an Integer class corresponding to the int type and a Double class corresponding to ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-array-conversion-java-toarray-methods
ArrayList to Array Conversion in Java : toArray() Methods - GeeksforGeeks
July 23, 2025 - We can use any of the following methods to convert an ArrayList to an array, depending on the type of array and your specific requirements. It is specified by toArray in interface Collection and interface List ... It returns an array containing all of the elements in this list in the correct order. ... import java.io.*; import java.util.List; import java.util.ArrayList; class GFG { public static void main(String[] args) { List<Integer> al = new ArrayList<Integer>(); al.add(10); al.add(20); al.add(30); al.add(40); Object[] objects = al.toArray(); // Printing array of objects for (Object obj : objects) System.out.print(obj + " "); } }
🌐
Codecademy
codecademy.com › docs › java › arraylist
Java | ArrayList | Codecademy
April 24, 2025 - The ArrayList is a dynamic array implementation in Java that provides flexible size, type safety, and convenient methods for data manipulation. Unlike traditional arrays with fixed sizes, ArrayLists dynamically expand and shrink as elements ...
🌐
Processing
processing.github.io › processing-javadocs › core › processing › data › IntList.html
IntList
Returns a normalized version of this array. Called getPercent() for consistency with the Dict classes. It's a getter method because it needs to returns a new list (because IntList/Dict can't do percentages or normalization in place on int values).
🌐
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.
🌐
BeginnersBook
beginnersbook.com › 2022 › 09 › convert-integer-list-to-int-array-in-java
Convert Integer List to int Array in Java
September 23, 2022 - Here, we are using toArray() method of ArrayList class to convert the given Integer ArrayList to int array. import java.util.*; public class JavaExample { public static void main(String[] args) { //A List of integers List<Integer> list= new ArrayList<>(); list.add(2); list.add(4); list.add(6); ...
🌐
Baeldung
baeldung.com › home › java › java list › working with a list of lists in java
Working With a List of Lists in Java | Baeldung
April 3, 2025 - On the other hand, List is more flexible on insertion and deletion operations, which run in O(1) time. Generally speaking, List is slower than Array on “get/set” operations. But some List implementations, such as ArrayList, are internally based on arrays.
🌐
GeeksforGeeks
geeksforgeeks.org › java › initializing-a-list-in-java
Initializing a List in Java - GeeksforGeeks
Fruits: [Apple, Banana, Mango] Colors: [Red, Green, Blue] Languages: [Java, Python, C++] First fruit: Apple Number of colors: 3 · List is an interface, and the instances of List can be created in the following ways: List a = new ArrayList(); List b = new LinkedList(); List c = new Vector(); List d = new Stack(); Before using a List, you need to import it from Java.util package: import java.util.List; import java.util.ArrayList; import java.util.Arrays; You can declare a List using the interface type.
Published   October 11, 2025
🌐
Renater
sourcesup.renater.fr › www › intcolls › javadoc › fr › univNantes › intcolls › ArrayIntList.html
ArrayIntList (Integer Collections)
This class implements a List by an Array of integer. Unlike ArrayList the array contains directly integers and not references on Integer objects · Author: Pierre-Olivier Terrisse
🌐
Baeldung
baeldung.com › home › java › java collections › guide to the java arraylist
Guide to the Java ArrayList | Baeldung
December 14, 2024 - ArrayList is a List implementation built atop an array that can dynamically grow and shrink as we add/remove elements. We can easily access an element by its index starting from zero.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-initialize-an-arraylist
How to Initialize an ArrayList in Java
For example, if you want all 50 ... ArrayListExample { public static void main(String args[]) { ArrayList<Integer> intlist = new ArrayList<>(Collections.nCopies(10, 5)); System.out.println("ArrayList items: "+intlist); } }...