List myList = new ArrayList();

or with generics (Java 7 or later)

List<MyType> myList = new ArrayList<>();

or with generics (Old java versions)

List<MyType> myList = new ArrayList<MyType>();
Answer from Dan Vinton on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › initializing-a-list-in-java
Initializing a List in Java - GeeksforGeeks
Choose an implementation or initialization method based on the requirement. Add elements using add() for mutable Lists. Access elements using get() and the index. The most common way to create a mutable List is by using the ArrayList class.
Published: August 26, 2026
Discussions

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 a List in Java - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... I tried to use List in Java but it says "symbol not found". More on stackoverflow.com
🌐 stackoverflow.com
Multiple ways to declare a list(JAVA)?
The use of List without the generic argument, is called a raw-type. You shouldn't use those. The generics are used to tell the compiler what type it should accept/return from this list... List badList = new ArrayList(); badList.add(1); badList.add("Boom"); badList.add(badList); The preferred forms are: List numbers = new ArrayList<>(); Or maybe: var numberList = new ArrayList(); Note: If you know how many items you'll be adding you can also supply a capacity for the ArrayList. More on reddit.com
🌐 r/learnprogramming
7
2
January 18, 2023
What is the best way to add items to a list?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
20
12
April 22, 2022
🌐
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).
🌐
Sentry
sentry.io › sentry answers › java › how do i create a new list in java?
Java Create a New List with ArrayList and List.of | Sentry
September 17, 2026 - This is useful if you need your list to be read-only. The ArrayList class implements the List interface. Here’s an example: import java.util.ArrayList; import java.util.Arrays; import java.util.List; class Main { public static void main(String[] args) { List<String> snackList = new ArrayList<>(Arrays.asList("Apple", "Baguette", "Chai")); System.out.println("My List: " + snackList); // Prints My List: [Apple, Baguette, Chai] } }
🌐
Baeldung
baeldung.com › home › java › java list › java list initialization in one line
Java List Initialization in One Line | Baeldung
April 4, 2025 - Instead, it’s a List backed by the original array, which has two implications that we’ll look at in the rest of this section. Although the class’s name happens to be ArrayList, it’s in the java.util.Arrays package.
🌐
How to do in Java
howtodoinjava.com › home › collections framework › create a java list with a single element (list.of, singletonlist)
Create a Java List with a Single Element (List.of, singletonList)
3 weeks ago - It returns an ArrayList today, but Collectors.toCollection(ArrayList::new) states that intent in code. List<String> collected = Stream.of("pizza").collect(Collectors.toCollection(ArrayList::new)); // [pizza] List<String> readOnly = Stream.of("pizza").toList(); // [pizza] The same choice exists for sets and maps. The factory methods from Java 9 reject null, while the older Collections methods accept it, and all of them are immutable.
🌐
TutorialsPoint
tutorialspoint.com › article › how-do-you-create-a-list-in-java
How do you create a list in Java?
March 14, 2026 - Use generic ArrayList<>() for modifiable lists with type safety. Use Arrays.asList() for quick fixed-size initialization, or wrap it in new ArrayList<>() if you need to add or remove elements later.
Find elsewhere
🌐
Wikihow
wikihow.com › computers and electronics › internet › website application instructions › how to initialize a list in java: 7 step-by-step methods
How to Initialize a List in Java: 7 Step-by-Step Methods
January 3, 2024 - Use the following code snippet to make your mutable list: List<String> listDogs = new ArrayList<>(Arrays.asList(dogs)); ... Use the add() method to add to your list. The following code will print your initial list and your modified list.
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java list – how to create, initialize & use list in java
Java List - How To Create, Initialize & Use List In Java
April 1, 2025 - Answer: The list is an interface in Java that extends from the Collection interface. The classes ArrayList, LinkedList, Stack, and Vector implement the list interface. Thus a programmer can use these classes to use the functionality of the list interface. ... Answer: ArrayList is a dynamic array. It is a resizable collection of elements and implements the list interface. ArrayList internally makes use of an array to store the elements.
🌐
Habr
habr.com › en › articles › 770790
List in Java | Interface, Methods, Example / Habr
October 30, 2023 - → Java 1.7 onwards, we can use a diamond operator · The List interface has several methods: • void add(int index, E element): This method is used to insert an object at a particular position in the list.
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › java list initialization in one line: list.of and arraylist
Java List Initialization in One Line: List.of and ArrayList
3 weeks ago - These two options are useful in code that must run on Java 8, and in cases where a read-only view of another list is what we need. The method Collections.unmodifiableList() returns an unmodifiable view of the list we pass. The view throws an UnsupportedOperationException on every change, but it shows the changes that other code makes to the source list.
🌐
Medium
medium.com › @kouomeukevin › the-only-guide-you-need-to-work-with-java-lists-fb24c4e9a179
The Only Guide You Need To Work With Java Lists | by Kevin Kouomeu | Medium
June 7, 2024 - To create a List in Java, you need to import the java.util.List package and choose an implementation class such as ArrayList, LinkedList, or Vector.
🌐
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?

🌐
W3Schools
w3schools.com › java › java_list.asp
Java List
The List interface is part of the Java Collections Framework and represents an ordered collection of elements.
🌐
Runestone Academy
runestone.academy › ns › books › published › apcsareview › ListBasics › listDeclareAndCreate.html
9.9. Declaring Lists — AP CSA Java Review - Obsolete
In the code below we are declaring ... actually create a list. It only creates a variable that can refer to a list. To actually create a list use new ArrayList<Type>(). If you leave off the <Type> it will default to Object....
🌐
IncludeHelp
includehelp.com › java › how-to-create-a-list-using-listof-method.aspx
How to create a list using List.of() method?
February 4, 2024 - To create a list using the List.of() method, specify the type class (Integer, String, etc.), and use the List.of() method by passing the elements of the list. ... This example creates a list of integers using List.of() method. // Importing the required classes import java.util.List; // The ...
🌐
Tejas' Insights
tejasgshinde.hashnode.dev › how-to-create-and-manipulate-lists-in-java-a-step-by-step-guide
Creating & Manipulating Lists in Java - Tejas' Insights
March 30, 2023 - We learned how to import the List class, create ArrayLists and LinkedLists, add and remove elements from a List, access elements by index, check the size of a List, and iterate through a List using a for-each loop. Lists are powerful data structures in Java that are used extensively in many programming applications.
🌐
CodeJava
codejava.net › java-core › collections › java-list-collection-tutorial-and-examples
Java List Collection Tutorial and Examples
February 10, 2025 - The following picture illustrates a list that stores some String elements:A list can store objects of any types. Primitive types are automatically converted to corresponding wrapper types, e.g. integer numbers are converted to Integer objects. It allows null and duplicate elements, and orders them by their insertion order (index).The following class diagram depicts the primary methods defined in the java.util.List interface:The List is the base interface for all list types, and the ArrayList and LinkedList classes are two common List’s implementations.
🌐
Simplilearn
simplilearn.com › home › resources › software development › an introduction to list in java
An Introduction to List in Java [With Examples]
May 11, 2021 - List in Java provides a way to maintain the ordered collection, and contains the index-based method to insert, delete, update, etc. Learn about list in java!
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States