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
🌐
Dot Net Perls
dotnetperls.com › arraylist-integer-java
Java - ArrayList int, Integer Examples - Dot Net Perls
We create an ArrayList and add those ints as Integers in a for-loop. Info The add() method receives an Integer. And we can pass an int to this method—the int is cast to an Integer. import java.util.ArrayList; public class Program { public static void main(String[] args) { int[] ids = {
Discussions

arrays - How to convert int[] into List<Integer> in Java? - Stack Overflow
How do I convert int[] into List in Java? Of course, I'm interested in any other answer than doing it in a loop, item by item. But if there's no other answer, I'll pick that one as ... More on stackoverflow.com
🌐 stackoverflow.com
arrays - How can I convert List<Integer> to int[] in Java? - Stack Overflow
Also, since the Integer type in ... because List#stream() returns a Stream, we can also skip it which leaves us with ... Sign up to request clarification or add additional context in comments. ... Save this answer. ... Show activity on this post. Unfortunately, I don't believe there really is a better way of doing this due to the nature of Java's handling of primitive types, boxing, arrays and ... More on stackoverflow.com
🌐 stackoverflow.com
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
Understanding convering ArrayList<int[]> to an int [][];
Assuming Java since you did not specify. In Java, generic types are "type erased". What this means is that the generic code doesn't actually know what type it is operating on. Imagine if you were to write some container just using Object everywhere, and then do casts to/from Object. Java generics basically just automate that casting for you. (Side note: "type erased" means something completely different in C++, so if you are familiar with that concept, don't confuse them.) A consequence of this type erasure is that you can't do things like T x = new T(); in generic code, because that actually requires knowing the type T so that its constructor can be called. So, if you look at ArrayList.toArray, you will see one version that doesn't take any parameters, and returns Object[]. This is a consequence of the above. However, you can pass it array of the correct type, if you like, and it can fill that. If the array you pass isn't big enough, it can introspect that object and get its class, and call the constructor from there. Overall this is a really ugly wart in the design of Java generics, but it is what it is. More on reddit.com
🌐 r/learnprogramming
2
3
July 20, 2022
🌐
Delft Stack
delftstack.com › home › howto › java › java arraylist of ints
How to Get ArrayList of Int Array in Java | Delft Stack
February 22, 2025 - These lines add two int arrays to the ArrayList listOfArrays, demonstrating the ability to store multiple arrays within the ArrayList. This process can be repeated to add multiple int arrays, providing a flexible and dynamic structure for storing arrays of integers. Accessing an element or an int array in an ArrayList in Java ...
🌐
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 the double type, and so on. The first step to being able to store a list ...
🌐
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 - 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 › arraylist-in-java
ArrayList in Java - GeeksforGeeks
Note: ArrayList cannot hold primitive types like int, double, or char directly. we must use their wrapper classes instead: ... It implements List Interface which is a sub-interface of Collection Interface.
Published   May 12, 2026
🌐
W3Docs
w3docs.com › java
ArrayList of int array in java | W3Docs
This creates an ArrayList that can hold arrays of int values. You can add an int array to the list using the add method:
Find elsewhere
🌐
Techie Delight
techiedelight.com › home › java › convert int array to list of integer in java
Convert int array to List of Integer in Java | Techie Delight
1 week ago - Convert the specified primitive array to a sequential stream using Arrays.stream(). Box each element of the stream to an Integer using IntStream.boxed(). Use Collectors.toList() to accumulate the input elements into a new list.
🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... An ArrayList is like a resizable array. It is part of the java.util package and implements the List interface.
🌐
Java67
java67.com › 2019 › 03 › how-to-convert-int-array-to-arraylist-in-java-8-example.html
How to convert int array to ArrayList of Integer in Java 8? [Example/Tutorial] | Java67
In fact, there was no shortcut to convert an int[] to ArrayList<Integer> or long[] to ArrayList<Long> till Java 8. From JDK 8 onwards, you either had to make a utility method or need to use general-purpose Java libraries like Google Guava or Apache Commons to convert an array of primitive values.
🌐
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
🌐
BeginnersBook
beginnersbook.com › 2022 › 09 › convert-integer-list-to-int-array-in-java
Convert Integer List to int Array in Java
September 23, 2022 - Convert Stream<Integer> to int array using toArray() method. import java.util.*; class JavaExample { public static void main(String[] args) { // List of Integer type List<Integer> arrList = new ArrayList<>(); arrList.add(1); arrList.add(3); arrList.add(5); arrList.add(7); arrList.add(9); ...
🌐
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 - // Java Program to convert an ArrayList // Containing Integers to primitive int array import java.util.ArrayList; //ArrayList convert into the primitive int array public class GFGexample { //main method public static void main(String[] args) { // Create the ArrayList named as arrayList ArrayList<Integer> arrayList = new ArrayList<>(); arrayList.add(10); arrayList.add(50); arrayList.add(100); arrayList.add(150); // Convert ArrayList<Integer> to int[] int[] intArray = convertToIntArray(arrayList); // print the result System.out.print("Original ArrayList: " + arrayList); System.out.println("\nCon
Top answer
1 of 16
1073

With streams added in Java 8 we can write code like:

int[] example1 = list.stream().mapToInt(i->i).toArray();
// OR
int[] example2 = list.stream().mapToInt(Integer::intValue).toArray();

Thought process:

  • The simple Stream#toArray returns an Object[] array, so it is not what we want. Also, Stream#toArray(IntFunction<A[]> generator) which returns A[] doesn't do what we want, because the generic type A can't represent the primitive type int

  • So it would be nice to have some kind of stream which would be designed to handle primitive type int instead of the reference type like Integer, because its toArray method will most likely also return an int[] array (returning something else like Object[] or even boxed Integer[] would be unnatural for int). And fortunately Java 8 has such a stream which is IntStream

  • So now the only thing we need to figure out is how to convert our Stream<Integer> (which will be returned from list.stream()) to that shiny IntStream.

    Quick searching in documentation of Stream while looking for methods which return IntStream points us to our solution which is mapToInt(ToIntFunction<? super T> mapper) method. All we need to do is provide a mapping from Integer to int.

    Since ToIntFunction is functional interface we can also provide its instance via lambda or method reference.

    Anyway to convert Integer to int we can use Integer#intValue so inside mapToInt we can write:

    mapToInt( (Integer i) -> i.intValue() )
    

    (or some may prefer: mapToInt(Integer::intValue).)

    But similar code can be generated using unboxing, since the compiler knows that the result of this lambda must be of type int (the lambda used in mapToInt is an implementation of the ToIntFunction interface which expects as body a method of type: int applyAsInt(T value) which is expected to return an int).

    So we can simply write:

    mapToInt((Integer i)->i)
    

    Also, since the Integer type in (Integer i) can be inferred by the compiler because List<Integer>#stream() returns a Stream<Integer>, we can also skip it which leaves us with

    mapToInt(i -> i)
    
2 of 16
265

Unfortunately, I don't believe there really is a better way of doing this due to the nature of Java's handling of primitive types, boxing, arrays and generics. In particular:

  • List<T>.toArray won't work because there's no conversion from Integer to int
  • You can't use int as a type argument for generics, so it would have to be an int-specific method (or one which used reflection to do nasty trickery).

I believe there are libraries which have autogenerated versions of this kind of method for all the primitive types (i.e. there's a template which is copied for each type). It's ugly, but that's the way it is I'm afraid :(

Even though the Arrays class came out before generics arrived in Java, it would still have to include all the horrible overloads if it were introduced today (assuming you want to use primitive arrays).

🌐
Ducmanhphan
ducmanhphan.github.io › 2022-04-17-how-to-convert-int-to-list-integer
How to convert int[] to List of Integer
public interface IntStream extends BaseStream<Integer, IntStream> { ... public static IntStream of(int... values) { return Arrays.stream(values); } ... } Using the improved version of Arrays.stream() in Java 16+. List<Integer> data = Arrays.stream(rawData) .boxed() .toList(); int[] rawData = {1, 3, 5}; List<Integer> data = new ArrayList<Integer>(); Collections.addAll(data, Arrays.stream(rawData).boxed().toArray(Integer::new)); Then, below is the definition of Collections.addAll() method.
🌐
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?

🌐
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...
🌐
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); ..
🌐
Reddit
reddit.com › r/learnprogramming › understanding convering arraylist to an int [][];
r/learnprogramming on Reddit: Understanding convering ArrayList<int[]> to an int [][];
July 20, 2022 -

I have noticed the syntax to convert an ArrayList<int[]> to a 2-d array (int[][]) is

arrName.toArray(new int[0][0]);

I am most curious about the parameters that we are sending into the toArray() method, and am curious how 'new int[0][0]' indicates this .