Almost always List is preferred over ArrayList because, for instance, List can be translated into a LinkedList without affecting the rest of the codebase.

If one used ArrayList instead of List, it's hard to change the ArrayList implementation into a LinkedList one because ArrayList specific methods have been used in the codebase that would also require restructuring.

You can read about the List implementations here.

You may start with an ArrayList, but soon after discover that another implementation is the more appropriate choice.

Answer from kgiannakakis on Stack Overflow
🌐
Reddit
reddit.com › r/javahelp › list vs array vs arraylist
r/javahelp on Reddit: List vs Array vs ArrayList
September 12, 2023 -

Coming from Python, this whole Java thing is incredibly confusing. The thing is, they don't seem to mix and uses different methods such as .size() vs .length(). All of them also seem to be doing the same thing: having a group of something.

I really need a comparison of the three, and how to declare, manipulate, and access, etc them.

Top answer
1 of 5
16
These are three different things: Array - a very basic data structure. It has a fixed, predetermined size that must be known at the time of creating (instantiating) the array. Think of it as a sorting box with several slots. Here, you have .length - without parentheses as it is a property, not a method List - an interface (not a class) that defines certain behavior. It cannot be instantiated on its own. ArrayList - a concrete class that implements the List interface. When you see a declaration like List data = new ArrayList<>(); there are several things going on: Listprogramming against the interface - here, the interface List is used as data type - this is good practice as it allows you to at any time change the internal representation of the List - e.g. from ArrayList to LinkedList if you figure out that the other better suits your needs. this is a data type identifier. It limits the type of elements that can be stored in the list. Here, only String objects are allowed. If you were to omit this, the list would store Object (the ancestor of all Java classes) and descendant instances (i.e. Object and any subclass of it). data - just the variable name new - the keyword to create a new Object Instance ArrayList<>() - the constructor call. Here, the constructor without parameters of the ArrayList class is called. The diamond operator <> is used to infer (take) the data type for the ArrayList from the variable type (here String). So, the whole is: we create a new variable of type List that can only accept String elements and ist internally represented as ArrayList.
2 of 5
4
Array An array is a data structure built into the Java language which can hold a number of elements, all of the same type. It cannot be resized once it has been created, and you cannot add elements to it without specifying an index. // creates an array of 10 ints int[] arr = new int[10]; // sets the value of the 0th element to 5 arr[0] = 5; // prints the value of the 0th element, which is 5 System.out.println(arr[0]); // Sets e to the value of the 0th element of arr, which is 5 int e = arr[0]; // Sets the value of the 1st element to 6 arr[1] = 6; // prints the length of arr System.out.println(arr.length); // even though arr[9] has not been set, // all elements initialize to 0 when first created System.out.println(arr[9]); /* Illegal operations! */ // an exception is thrown since arr can only hold 10 elements System.out.println(arr[11]); // there is no shorthand syntax to get the last element of an array System.out.println(arr[-1]); // length is a variable, not a method System.out.println(arr.length()); // arr can only hold ints arr[2] = "Hello"; List A List is an class that is part of the Java Standard Library which allows for dynamic insertion and deletion of elements. You can't just create a List though, you have to use one of its subclasses, which includes ArrayList, and you have to use generics as well. Think of an ArrayList as a dynamic version of an array, and is the closest thing to Python's list datatype. // Make sure to import these at the top of your class! import java.util.List; import java.util.ArrayList; // creates an ArrayList of ints List myList = new ArrayList<>(); // adds 5 to myList myList.add(5); // prints the 0th element of myList, which is 5 System.out.println(myList.get(0)); myList.add(6); // removes the last element of myList, which is 6 int removed = myList.remove(); // prints the size of the list, which is 1 System.out.println(myList.size()); /* Illegal operations! */ // myList only has 1 element System.out.println(list.get(5)); myList.remove(); // removes 5 // throws an exception since the list is empty myList.remove(); // throws an exception since myList can only take ints myList.add("Hello"); // you can only use bracket notation on arrays System.out.println(myList[0]); // size is a method, not a variable System.out.println(myList.size); Other Info There are lots of other List subclasses you can use depending on the kind of operations you want to do on it, such as Queues, LinkedLists, and PriorityQueues. The reason why we use Integer instead of int when working with Lists is a limitation of the Java language. Generic types can only be object types, but primitive types, such as int, double, boolean, etc., are not object types, and thus we have to use autoboxing to work with primitives in this manner.
🌐
GeeksforGeeks
geeksforgeeks.org › java › difference-between-list-and-arraylist-in-java
Difference between List and ArrayList in Java - GeeksforGeeks
July 15, 2025 - Now dwelling on the next concept of ArrayList in java. So ArrayList is basically a part of the collection framework and is present in java.util package. It provides us with dynamic arrays in Java. This class implements the List interface. Similar to a List, the size of the ArrayList is increased automatically if the collection grows or shrinks if the objects are removed from the collection.
Discussions

What's the different between ArrayList and List?
Oshedhe Munasinghe is having issues with: Now I am really confused and I don't think I'm the only one who got mixed. What is the different between ArrayList and List? I know the... More on teamtreehouse.com
🌐 teamtreehouse.com
4
February 25, 2016
Difference in ArrayList<> list = new ArrayList<>() VS List<> list = new ArrayList<>()
ArrayList list = new ArrayList<>() has three parts: The declaration of the variable, list with its type being the concrete class ArrayList: ArrayList list The creation of an object: new ArrayList<>() creates an instance of the ArrayList, with the inferred generic type of Assignment (via =) of the instance to the list With List list = new ArrayList<>(), both #2 and #3 are the same, but the list is now declared to be the less-specific type (an interface, in this case) of List. The difference isn't in the object created (both are the same), it's in what you can do with the variable, as well as what the intention of the variable is. For example, declaring ArrayList<> list, you can call list.trimToSize(), but you can't call that method on a variable declared like List<> list, because trimToSize() only exists on ArrayList. This may seem like a minor issue, but there are many other implementations of List that you won't instantiate, e.g., those created by List.of() and as the result of a stream() operation that ends with .toList(). The other reason is intent: if you say List list, then the reader knows there's nothing special about which implementation will be used. If you write ArrayList list, then you're implying that you really want and need only the concrete ArrayList for some reason (which is unlikely). In general, Java code should declare the least specific type for variables. That means List instead of ArrayList, Map instead of HashMap, etc. More on reddit.com
🌐 r/javahelp
10
7
March 5, 2023
What's the difference between an ArrayList and a List?
ArrayList is a remnant of .NET 1.0 before generics were added to the language. Don't use ArrayList in any new code and replace old code with List. Even List is better. More on reddit.com
🌐 r/csharp
19
15
November 7, 2020
what is the diffrence between list and ArrayList?
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 - best also formatted as code block 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. 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/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) 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/learnjava
8
11
December 17, 2022
Top answer
1 of 15
502

Almost always List is preferred over ArrayList because, for instance, List can be translated into a LinkedList without affecting the rest of the codebase.

If one used ArrayList instead of List, it's hard to change the ArrayList implementation into a LinkedList one because ArrayList specific methods have been used in the codebase that would also require restructuring.

You can read about the List implementations here.

You may start with an ArrayList, but soon after discover that another implementation is the more appropriate choice.

2 of 15
131

I am wondering if anyone uses (2)?

Yes. But rarely for a sound reason (IMO).

And people get burned because they used ArrayList when they should have used List:

  • Utility methods like Collections.singletonList(...) or Arrays.asList(...) don't return an ArrayList.

  • Methods in the List API don't guarantee to return a list of the same type.

For example of someone getting burned, in https://stackoverflow.com/a/1481123/139985 the poster had problems with "slicing" because ArrayList.sublist(...) doesn't return an ArrayList ... and he had designed his code to use ArrayList as the type of all of his list variables. He ended up "solving" the problem by copying the sublist into a new ArrayList.

The argument that you need to know how the List behaves is largely addressed by using the RandomAccess marker interface. Yes, it is a bit clunky, but the alternative is worse.

Also, how often does the situation actually require using (1) over (2) (i.e. where (2) wouldn't suffice..aside 'coding to interfaces' and best practices etc.)

The "how often" part of the question is objectively unanswerable.

(and can I please get an example)

Occasionally, the application may require that you use methods in the ArrayList API that are not in the List API. For example, ensureCapacity(int), trimToSize() or removeRange(int, int). (And the last one will only arise if you have created a subtype of ArrayList that declares the method to be public.)

That is the only sound reason for coding to the class rather than the interface, IMO.

(It is theoretically possible that you will get a slight improvement in performance ... under certain circumstances ... on some platforms ... but unless you really need that last 0.05%, it is not worth doing this. This is not a sound reason, IMO.)


You can’t write efficient code if you don’t know whether random access is efficient or not.

That is a valid point. However, Java provides better ways to deal with that; e.g.

public <T extends List & RandomAccess> void test(T list) {
    // do stuff
}

If you call that with a list that does not implement RandomAccess you will get a compilation error.

You could also test dynamically ... using instanceof ... if static typing is too awkward. And you could even write your code to use different algorithms (dynamically) depending on whether or not a list supported random access.

Note that ArrayList is not the only list class that implements RandomAccess. Others include CopyOnWriteList, Stack and Vector.

I've seen people make the same argument about Serializable (because List doesn't implement it) ... but the approach above solves this problem too. (To the extent that it is solvable at all using runtime types. An ArrayList will fail serialization if any element is not serializable.)


Finally, I'm not going to say "because its is good style". That "reason" is both a circular argument ("Why is it 'good style'?") and an appeal to an unstated (and probably non-existent!) higher authority ("Who says it is 'good style'?").

(I do think it is good style to program to the interface, but I'm not going to give that as a reason. It is better for you to understand the real reasons and come to the (IMO) correct conclusions for yourself. The correct conclusion may not always be the same ... depending on the context.)

🌐
W3Schools
w3schools.com › java › java_arraylist.asp
Java ArrayList
Since ArrayList implements the List interface, this is possible. It works the same way, but some developers prefer this style because it gives them more flexibility to change the type later. For a complete reference of ArrayList methods, go to our Java ArrayList Reference.
Top answer
1 of 3
2
As @La Gracchiatrice (https://teamtreehouse.com/lagracchiatrice) said above, List is an interface so you cannot write something like: java List myList = new List(); You need to choose one of the implementations of List, like ArrayList or LinkedList: ```java List myList = new ArrayList(); List myList = new LinkedList(); ``` One consideration is whether to define the list as List or ArrayList. If you do something like: java List myList = new ArrayList(); then you can only call those methods that are in the List interface. So if the ArrayList class has some additional methods, which it does, you cannot call those methods on myList variable. However, if you defined your list as: java ArrayList myList = new ArrayList(); then you can call those addtional methods in ArrayList on myList, in addition to all the ones in the List interface that the ArrayList class has already implemented. So now the question is why define myList as List ? Why not always define it as ArrayList ? Well, one advantage of defining it as a List is that if at some point you decided to change the implementation of your list from ArrayList to LinkedList then all you have to do is to change the line: java List myList = new ArrayList(); to: java List myList = new LinkedList(); and nothing else needs to change, but if myList was of type ArrayList and you had used ArrayList specific methods then you have to make more changes to your code.
2 of 3
1
Grigorij you are forgiven! :) La Gracchiatrice Thank you for the information. If you don't mind do you have any code examples? Can't find it in google.. :( (btw. guys how did you do emoji?)
🌐
Medium
medium.com › @shristikumari-blog › list-vs-arraylist-the-one-java-concept-youll-actually-understand-today-3e638566961c
List vs ArrayList in Java: Understand the Difference in Minutes | by Shristi | Medium
October 1, 2025 - LinkedList = In Doubly linked list, better for frequent insertions/deletions. Stack = A subclass of Vector (LIFO). ... In Java, an ArrayList is a resizable array implementation of the List interface, provided as part of the Java Collections ...
Find elsewhere
🌐
BYJUS
byjus.com › gate › difference-between-list-and-arraylist-in-java
Difference Between List and ArrayList in Java
September 28, 2022 - Both of these are members of the Collection framework, but there is a major difference between List and ArrayList in Java. The List refers to a collection of various elements in a sequence, in which every element is basically an object. Also, ...
🌐
Baeldung
baeldung.com › home › java › java array › array vs. list performance in java
Array vs. List Performance in Java | Baeldung
March 7, 2025 - In contrast, ArrayList creation involves additional overhead, such as initializing internal data structures and dynamically resizing the list as elements are added. Let’s remember that actual performance can vary depending on various factors, such as the size of the collection, the hardware on which the code is executed, and the Java version you use.
🌐
Baeldung
baeldung.com › home › java › java list › list vs. arraylist in java
List vs. ArrayList in Java | Baeldung
December 9, 2025 - ArrayList is one of the most commonly used List implementations in Java. It’s built on top of an array, which can dynamically grow and shrink as we add/remove elements.
🌐
TutorialsPoint
tutorialspoint.com › article › difference-between-list-and-arraylist-in-java
Difference Between List and ArrayList in Java
June 23, 2023 - Insertion and deletion operations in ArrayList are slower than that of List. When we insert a new element to an existing ArrayList, the elements below that are shifted to the next index.
🌐
Scaler
scaler.com › home › topics › arraylist vs linkedlist in java
ArrayList vs LinkedList in Java - Scaler Topics
April 3, 2024 - In contrast, LinkedList offers O(1) time complexity for insertions and removals but O(n) for index-based access, as it requires traversing the list. When ArrayList is declared in the program the JVM(Java Virtual Machine) allocates a memory block of contiguous memory locations according to the size given in the declaration.
🌐
GeeksforGeeks
geeksforgeeks.org › java › arraylist-vs-linkedlist-java
ArrayList vs LinkedList in Java - GeeksforGeeks
May 29, 2026 - ArrayList is based on a dynamic array, while LinkedList uses a doubly linked list · ArrayList provides faster random access, whereas LinkedList is efficient for frequent insertions and deletions · Both are part of the Java Collections Framework ...
🌐
Codecademy
codecademy.com › learn › learn-java › modules › learn-java-arrays-and-arraylists › cheatsheet
Learn Java: Arrays and ArrayLists Cheatsheet | Codecademy
While Java arrays are fixed in size (the size cannot be modified), an ArrayList allows flexibility by being able to both add and remove elements. ... An index refers to an element’s position within an array.
🌐
DevGenius
blog.devgenius.io › java-array-vs-arraylist-1453205edd63
Java Array vs ArrayList. In Java, both Array and ArrayList are… | by M Business Solutions | Dev Genius
December 9, 2024 - ArrayList<Integer> list = new ArrayList<>(); list.add(1); // Adding element list.add(2); list.remove(0); // Removing element at index 0 · Array: You can store both primitive types (int, float, etc.) and objects (Integer, String, etc.) in arrays. int[] numArray = {1, 2, 3}; // Stores primitives String[] strArray = {"Java", "Python"}; // Stores objects
🌐
Quora
quora.com › Why-would-you-ever-use-an-array-when-you-can-just-use-an-ArrayList-in-Java
Why would you ever use an array when you can just use an ArrayList in Java? - Quora
Answer (1 of 6): This question is like asking why you would ever use [code ]int[/code] when you have the [code ]Integer[/code] class. Java programmers seem especially zealous about everything needing to be wrapped, and wrapped, and wrapped. Yes, [code ]ArrayList [/code] does everything t...
🌐
xperti
xperti.io › home › 10 differences between array and arraylist in java
Array VS ArrayList in Java: How are they different?
May 6, 2022 - ArrayList<Integer> numList = new ... ArrayList is always single dimensional. Arraylist is based upon the properties of a list due to which it does operate beyond one dimension....
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › ArrayList.html
ArrayList (Java Platform SE 8 )
April 21, 2026 - The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation. Each ArrayList instance has a capacity.
🌐
DEV Community
dev.to › jacobisah › arraylist-vs-array-in-java-4cej
ArrayList vs Array In Java - DEV Community
August 17, 2022 - As you can see, we have an ArrayList and a type stringthat accepts names in the angle bracket <>. The ArrayList is then instantiated using =, angle brackets <>, and parentheses (). You may have noticed that we did not mention the size in the arraylist. This is due to the fact that ArrayListdoes not have a size provided.
🌐
How to do in Java
howtodoinjava.com › home › java array › java array vs. arraylist: comparison and conversion
Java Array vs. ArrayList: Comparison and Conversion
July 3, 2024 - Java ArrayList is part of the collection framework and implementation of resizable array data structure. Learn when to use array and arraylist.