๐ŸŒ
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. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ difference-between-list-and-arraylist-in-java
Difference between List and ArrayList in Java - GeeksforGeeks
July 15, 2025 - List interface is implemented by the classes of ArrayList, LinkedList, Vector, and Stack. List is an interface, and the instances of List can be created by implementing various classes. Geek if the above said sounds confusing then refer to the image below where you can easily spot the hierarchy and the List interface consisting of classes prior to landing upon implementation of List interface. ... // Java program to demonstrate the // working of a List with ArrayList // class // Importing all utility classes import java.util.*; // Main class public class GFG { // Main driver method public stat
Discussions

List vs Array vs ArrayList
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. More on reddit.com
๐ŸŒ r/javahelp
15
7
September 12, 2023
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
Can someone please explain the difference between List and ArrayList like I'm five?
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
29
30
October 2, 2021
Type List vs type ArrayList in Java - Stack Overflow
Something to note is that "ArrayList specific methods" isn't limited to just methods used in ArrayList, but their return types being changed as well (will cause a NoSuchMethodException between Java versions if the internal return type changes). An example of this is the change in the return ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
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. You can access elements by their index, add duplicates, and maintain the insertion order. Since List is an interface, you cannot create a List object directly. Instead, you use a class that implements the List interface, such as: ArrayList - like a resizable array with fast random access
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ array-vs-arraylist-in-java
Array vs ArrayList in Java - GeeksforGeeks
June 5, 2026 - Note: ArrayList is a dynamic-size data structure in Java that can automatically grow or shrink as elements are added or removed. It is part of the Java Collections Framework. ... The following common differences between Array and ArrayList are listed below with the help of examples.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ difference-between-list-and-arraylist-in-java
Difference Between List and ArrayList in Java
June 23, 2023 - A collection framework in Java consists of a set of classes and interfaces which helps in implementing various data structures. List and ArrayList belong to this collection framework. List is an interface and ArrayList is a class. Their main ...
๐ŸŒ
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.
๐ŸŒ
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 ...
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java list โ€บ list vs. arraylist in java
List vs. ArrayList in Java | Baeldung
December 9, 2025 - When using collections in Java it's conventional to use the interface types for our variables and fields, rather than the concrete types. We look at the difference between these two approaches.
Find elsewhere
๐ŸŒ
Tech Differences
techdifferences.com โ€บ home โ€บ difference between list and arraylist in java
Difference Between List and ArrayList in Java (with Comparison Chart) - Tech Differences
December 26, 2019 - The ArrayList class is used to create the dynamic arrays that grow and shrunk whenever required. The list created using ArrayList class is nothing but the array of objects. In Java, the standard array has the fixed length, so, you must know ...
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?)
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ can someone please explain the difference between list and arraylist like i'm five?
r/javahelp on Reddit: Can someone please explain the difference between List and ArrayList like I'm five?
October 2, 2021 -

What exactly is the difference between

List<String> inputs = new ArrayList<>()

and

ArrayList<String> inputs = new ArrayList<>()

I've read some stuff about it but I'm a bit confused and I don't feel like I understood completely. Can someone explain the difference with some examples? Thank you!

๐ŸŒ
iO Flood
ioflood.com โ€บ blog โ€บ java-list-vs-arraylist
Java List vs ArrayList: Detailed Differences and Uses
February 27, 2024 - While List and ArrayList can be used in similar ways, they offer different levels of functionality and flexibility. A List in Java is an interface, meaning itโ€™s a blueprint for how a data structure should behave. It provides a set of methods that any class implementing the List interface must have.
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.)

Top answer
1 of 6
24

List is in interface while ArrayList is a class.

See ArrayList, and List.

E.g, you can't use this setup:

List<String> list = new List<String>();... Because it's an interface.

However, this works:

ArrayList<String> arrayList = new ArrayList<String>();

Also... You can do as duffymo says below, which is more or less the same as implementing the List interface (making your own list implementation).

2 of 6
23

Consider a line like the following:

List<String> names = new ArrayList<String>();

If you're new to object-oriented architectures, you might have expected instead to see something like ArrayList<String> names = new ArrayList<String>();. After all, you've just said that it's a new ArrayList, so shouldn't you store it in a variable of type ArrayList?

Well, you certainly can do that. However, List is an interface--like a template of sorts--that ArrayList is said to inherit. It is a contract that says "anytime you use a List implementation, you can expect these methods to be available". In the case of List, the methods are things like add, get, etc.

But ArrayList is only one implementation of List. There are others, such as LinkedList. The two have the same interface, and can be used the same way, but work very differently behind the scenes. Where ArrayList is "random" access, meaning that it directly finds a specific element of the array without iterating through the whole list, LinkedList does have to start from the first element and go one-by-one until it gets to the element you need.

The thing is, while you do need to specify which you want when you create the object, you generally only need to communicate no more than the fact that it is a List, so you simply say that's what it is. List communicates that you have a collection that is intended to be in the order that it is given. If you don't need to communicate that much, you might consider passing it around as a Collection, which is another interface (a super-interface of List). Or, if all you need to communicate is that you can iterate over it, you might even call it an Iterable.

๐ŸŒ
Blogger
javarevisited.blogspot.com โ€บ 2016 โ€บ 01 โ€บ 9-difference-between-array-vs-arraylist-in-java.html
Difference between a List and Array in Java? ArrayList vs Array Example
Hello there, if you are wondering what is the difference between a list and an array, or particularly an ArrayList and an Array in Java then you have come to the right place. Earlier, I have shared the best data structure and algorithm courses and in this article, I will explain to you the differences and similarities between a list and an array in Java.
๐ŸŒ
Kensoft PH
kensoftph.com โ€บ arrays-vs-arraylists-in-java-key-differences-explained
Arrays vs ArrayLists in Java: Key Differences Explained
October 14, 2025 - Learn the difference between array and ArrayList in Java. Complete guide covering performance, use cases, and when to use each data structure with examples.
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ java-arrays-and-arraylists-a-comparative-look-bcbc97b32a1e
Java Arrays vs ArrayLists Guide | Medium
November 18, 2023 - To use an ArrayList, you first need to import it from the java.util package. An ArrayList can be declared as follows: ... Here, String indicates the type of objects the ArrayList will store, making it a type-safe collection. You can store any type of objects, including custom classes. One of the primary advantages of an ArrayList is its dynamic nature, allowing elements to be added at any time: ... The add method appends elements to the end of the list but can also insert elements at a specified index.
๐ŸŒ
Quora
quora.com โ€บ What-is-difference-between-list-and-ArrayList
What is difference between list and ArrayList? - Quora
By implementing the interface, we are saying that ArrayList implements every m ... I presume that by โ€œlistโ€ you mean โ€œListโ€, and specifically โ€œjava.util.Listโ€.
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ difference between array and arraylist
Difference Between Array and Arraylist | Simplilearn
September 11, 2025 - Array and arraylist are well known data structures in Java programming language that are used to store the elements or objects. Click here to learn more.
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States