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
import java.util.ArrayList; public class Program { public static void main(String[] args) { ArrayList<Integer> list = new ArrayList<>(); list.add(
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
java - Creating an ArrayList of integer arrays results in duplicate entries - Stack Overflow
I'm using the simple algorithm ... two lists with each list item containing 3 integers. Here's test code I'm trying out to build and display such a list. When I run the following code, it prints out the same numbers for each array in the ArrayList.... More on stackoverflow.com
🌐 stackoverflow.com
December 3, 2012
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
🌐
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));
🌐
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:
🌐
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.
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.
🌐
Delft Stack
delftstack.com › home › howto › java › convert int array to arraylist java
How to Convert Int Array to Arraylist in Java | Delft Stack
February 2, 2024 - We can cast the returned list to ArrayList<Integer>. import java.util.ArrayList; import java.util.Arrays; import java.util.stream.Collectors; public class IntToInteger { public static void main(String[] args) { int[] intArray = {10, 20, 30, 40}; ArrayList<Integer> integerArray = (ArrayList<Integer>) Arrays.stream(intArray).boxed().collect(Collectors.toList()); System.out.println(integerArray); } } Output: [10, 20, 30, 40] We can use the manual method to add every item of the array to the ArrayList.
🌐
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
🌐
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.
🌐
Coderanch
coderanch.com › t › 464780 › java › ArrayList-Integer
new ArrayList<Integer>({1,2,3,4}) (Beginning Java forum at Coderanch)
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); ..
🌐
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
🌐
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.
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).

🌐
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...
Top answer
1 of 4
14

First of all, several of the other answers are misleading and/or incorrect. Note that an array is an object. So you can use them as elements in a list, no matter whether the arrays themselves contain primitive types or object references.

Next, declaring a variable as List<int[]> list is preferred over declaring it as ArrayList<int[]>. This allows you to easily change the List to a LinkedList or some other implementation without breaking the rest of your code because it is guaranteed to use only methods available in the List interface. For more information, you should research "programming to the interface."

Now to answer your real question, which was only added as a comment. Let's look at a few lines of your code:

Integer[] point = new Integer[3];

This line creates an array of Integers, obviously.

for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 3; j++) {
        point[j] = (int)(Math.random() * 10);
    }            

    //Doesn't this line add filled Integer[] point to the 
    //end of ArrayList list?
    list.add(point);
    //...
}

Here you assign values to the elements of the array and then add a reference to the array to your List. Each time the loop iterates, you assign new values to the same array and add another reference to the same array to the List. This means that the List has 10 references to the same array which has been repeatedly written over.

Iterator it = list.iterator();
while (it.hasNext()) {
    point = (Integer[])it.next();
    for (int i = 0; i < 3; i++) {
        System.out.print(point[i] + ",");
    }
    System.out.println();
}

Now this loop prints out the same array 10 times. The values in the array are the last ones set at the end of the previous loop.

To fix the problem, you simply need to be sure to create 10 different arrays.

One last issue: If you declare it as Iterator<Integer[]> it (or Iterator<int[]> it), you do not need to cast the return value of it.next(). In fact this is preferred because it is type-safe.

Finally, I want to ask what the ints in each array represent? You might want to revisit your program design and create a class that holds these three ints, either as an array or as three member variables.

2 of 4
2

I would highly recommend to enclose the integer array of 3 numbers into a meaningful class, that would hold, display and control an array of 3 integers.

Then in your main, you can have an growing ArrayList of objects of that class.

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