you can define like this :

ArrayList<String>[] lists = (ArrayList<String>[])new ArrayList[10];
    lists[0] = new ArrayList<String>();
    lists[0].add("Hello");
    lists[0].add("World");
    String str1 = lists[0].get(0);
    String str2 = lists[0].get(1);
    System.out.println(str1 + " " + str2);
Answer from UVM on Stack Overflow
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › initialize an arraylist in java
Initialize an ArrayList in Java
August 4, 2023 - Java ArrayList can be initialized in one line using List.of(), and new ArrayList constructors. Learn to add elements one by one and in bulk.
🌐
GeeksforGeeks
geeksforgeeks.org › java › initialize-an-arraylist-in-java
Initialize an ArrayList in Java - GeeksforGeeks
July 11, 2025 - ArrayList inherits the AbstractList class and implements the List interface. ArrayList is initialized by a size, however, the size can increase if the collection grows or shrink if objects are removed from the collection.
Discussions

java - Initialize an Array of ArrayList - Stack Overflow
How can I initialize an Array of ArrayList ? I tried this syntax but it didn't work: ArrayList [] subsection = new ArrayList [4]; More on stackoverflow.com
🌐 stackoverflow.com
java - Initialization of an ArrayList in one line - Stack Overflow
However, I'm not too fond of that ... subclass of ArrayList which has an instance initializer, and that class is created just to create one object -- that just seems like a little bit overkill to me. What would have been nice was if the Collection Literals proposal for Project Coin was accepted (it was slated to be introduced in Java 7, but it's ... More on stackoverflow.com
🌐 stackoverflow.com
Initializing an empty ArrayList (Java)
Assuming both are not static variables the only difference should be the order of initialization. When you have something declared out of the constructor it is initialized first. It will run the constructor after all of the fields at the top have been initialized. Here is a stack overflow post about this topic which goes into more detail: https://stackoverflow.com/questions/4916735/default-constructor-vs-inline-field-initialization More on reddit.com
🌐 r/learnprogramming
3
9
March 31, 2018
A little warnings in implementation of stacks in java. This was working fine for my teacher but when I am implementing it, i get warnings. Please help me understand this
Read up on the terms "object instance", "static method", "non-static method", and "static member". What I write below won't make sense unless you understand those terms. I could explain them myself but it would take too long and there are thousands of resources about them online already. --------------------------------- You're calling static methods, like push(), from an instance of a Stack class. The entire point of a static method is that you do not need to create an instance of the class to use them. So calling push directly on the Stack class itself, like Stack.push(), will cause the red lines to go away. They're not errors per say, just warnings because it doesn't really make sense to call a static method from an object instance. But you have another thing here which may be a problem. Your list inside your Stack class is a static member, meaning that even if you do make an instance of the Stack class, all instances of your stack class will share the same ArrayList. // All of these isntances share the exact same ArrayList. Stack stackA = new Stack(); Stack stackB = new Stack(); Stack stackC = new Stack(); Does it actually make sense to make ArrayList static? If you make the ArrayList not static, what do you have to then change about your methods in the Stack class? More on reddit.com
🌐 r/learnjava
7
3
September 23, 2022
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-initialize-an-arraylist
How to Initialize an ArrayList in Java
You can initialize an ArrayList with elements using Arrays.asList(). In this methods, all elements can be specified inside asList() method as shown below. However you can add more elements later using add() method. import java.util.ArrayList; import java.util.Arrays; public class ArrayListExample ...
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java arraylist: how to declare, create, initialize arraylist
Java ArrayList: How to Declare, Create, Initialize ArrayList
March 5, 2026 - This method is used to initialize the ArrayList with the same values. We provide the count of elements to be initialized and the initial value to the method. ... The below example demonstrates Array initialization using Collections.nCopies method. import java.util.*; public class Main { public static void main(String args[]) { //create ArrayList with 10 elements //initialized to value 10 using Collections.nCopies ArrayList&amp;lt;Integer&amp;gt; intList = new ArrayList&amp;lt;Integer&amp;gt;(Collections.nCopies(10,10)); //print the ArrayList System.out.println(&amp;quot;Content of ArrayList:&amp;quot;+intList); } }
Top answer
1 of 16
2789

It would be simpler if you were to just declare it as a fixed-size List (but with mutable elements) - does it have to be an ArrayList?

List<String> places = Arrays.asList("Buenos Aires", "Córdoba", "La Plata");

Or if you have only one element:

List<String> places2 = Collections.singletonList("Buenos Aires");

This would mean that places2 is immutable (trying to change it in any way will cause an UnsupportedOperationException exception to be thrown).

To make a variable-size list that is a concrete ArrayList you can create an ArrayList from the fixed-size list:

ArrayList<String> places = new ArrayList<>(Arrays.asList("Buenos Aires", "Córdoba", "La Plata"));

And import the correct package:

import java.util.Arrays;
2 of 16
2240

Actually, probably the "best" way to initialize the ArrayList is the method you wrote, as it does not need to create a new List in any way:

ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");

The catch is that there is quite a bit of typing required to refer to that list instance.

There are alternatives, such as making an anonymous inner class with an instance initializer (also known as an "double brace initialization"):

ArrayList<String> list = new ArrayList<String>() {{
    add("A");
    add("B");
    add("C");
}};

However, I'm not too fond of that method because what you end up with is a subclass of ArrayList which has an instance initializer, and that class is created just to create one object -- that just seems like a little bit overkill to me.

What would have been nice was if the Collection Literals proposal for Project Coin was accepted (it was slated to be introduced in Java 7, but it's not likely to be part of Java 8 either.):

List<String> list = ["A", "B", "C"];

Unfortunately it won't help you here, as it will initialize an immutable List rather than an ArrayList, and furthermore, it's not available yet, if it ever will be.

🌐
Career Karma
careerkarma.com › blog › java › how to initialize arraylist in java
How to Initialize ArrayList in Java | Career Karma
December 1, 2023 - Type is the type of data our array list will store. arrayName is the name of the array list we are creating. new ArrayList<>() tells our program to create an instance of ArrayList and assign it to the arrayName variable.
Find elsewhere
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome › Unit7-ArrayList › topic-7-1-arraylist-basics.html
7.1. Intro to ArrayLists — CSAwesome v1
No, you can have an array of objects. An ArrayList has faster access to the last element than an array. No, an ArrayList is implemented using an array so it has the same access time to any index as an array does. An ArrayList resizes itself as necessary as items are added, but an array does not. An ArrayList is really a dynamic array (one that can grow or shrink as needed). The ArrayList class is in the java.util package.
🌐
freeCodeCamp
freecodecamp.org › news › how-to-initialize-an-arraylist-in-java-with-values
How to Initialize an ArrayList in Java – Declaration with Values
April 21, 2023 - Declaration has to do with creating a data structure, while initialization involves assigning values to the data structure. ... import java.util.ArrayList; public class ArrayListTut { public static void main(String[] args) { ArrayList<String> ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-of-arraylist-in-java
ArrayList of ArrayList in Java - GeeksforGeeks
July 11, 2025 - // Java code to demonstrate the ... int n = 3; // Here aList is an ArrayList of ArrayLists ArrayList<ArrayList<Integer> > aList = new ArrayList<ArrayList<Integer> >(n); // Create n lists one by one and append to the // master ...
🌐
Dot Net Perls
dotnetperls.com › initialize-arraylist-java
Java - ArrayList Initialize - Dot Net Perls
In this example, we use a String array to initialize an ArrayList. We create an empty ArrayList of Strings. Then We invoke the Collections.addAll method. This method receives two arguments. Argument 1 The first argument to Collections.addAll is the ArrayList we want to add elements to.
🌐
iO Flood
ioflood.com › blog › java-initialize-arraylist
Initialize an ArrayList in Java: Easy and Advanced Methods
February 27, 2024 - In Java, the simplest way to initialize an ArrayList involves using the ‘new’ keyword and the ‘ArrayList’ constructor. This method is perfect for beginners and is often used in a wide range of Java programs.
🌐
TutorialsPoint
tutorialspoint.com › article › initialize-an-arraylist-in-java
Initialize an ArrayList in Java
March 18, 2025 - Below is an example of initializing an ArrayList with the asList() method ? import java.util.*; public class Demo { public static void main(String args[]) { ArrayList<Integer> myList = new ArrayList<Integer>(Arrays.asList(50,29,35,11,78,64,89,67)); ...
🌐
SourceBae
sourcebae.com › home › how to initialization of an arraylist in one line?
How to Initialization of an ArrayList in one line? - SourceBae
August 21, 2025 - What it is: Double brace initialization is a way of initializing an ArrayList using an anonymous inner class and an instance initializer block. Example code snippet: ArrayList<String> names = new ArrayList<String>() {{ add("Alice"); add("Bob"); ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-array-of-arraylist-of-array
Java Array of ArrayList, ArrayList of Array | DigitalOcean
August 4, 2022 - If you are not sure about the type of objects in the array or you want to create an ArrayList of arrays that can hold multiple types, then you can create an ArrayList of an object array. Below is a simple example showing how to create ArrayList of object arrays in java.
🌐
Coderanch
coderanch.com › t › 661245 › java › set-arraylist
Is this the best way to set up an arraylist? (Beginning Java forum at Coderanch)
January 25, 2016 - JavaRanch-FAQ HowToAskQuestion... ... When you use a Collection type you should always specify the type of the Collection. List<Integer> myList = new ArrayList<Integer>();...
🌐
Java67
java67.com › 2015 › 10 › how-to-declare-arraylist-with-values-in-java.html
How to declare ArrayList with values in Java? Examples | Java67
That's all about how to declare an ArrayList with values in Java. You can use this technique to declare an ArrayList of integers, String, or any other object. It's truly useful for testing and demo purpose, but I have also used this to create an ArrayList of an initial set of fixed values.
🌐
Baeldung
baeldung.com › home › java › java list › initialize an arraylist with zeroes or null in java
Initialize an ArrayList with Zeroes or Null in Java | Baeldung
March 7, 2025 - We use the function setSize() to initialize the Vector with the desired number of elements. After that, the Vector will fill itself with null values. We must consider that this method only helps us if we want to insert null values ​​in our list.
🌐
Baeldung
baeldung.com › home › java › java list › java list initialization in one line
Java List Initialization in One Line | Baeldung
April 4, 2025 - The name “double-brace initialization” is quite misleading. While the syntax may look compact and elegant, it dangerously hides what is going on under the hood. There isn’t actually a double-brace syntax element in Java; those are two blocks formatted intentionally this way. With the outer braces, we declare an anonymous inner class that will be a subclass of the ArrayList...