The biggest difference is that you can add to and remove from a list, whereas arrays have a fixed size. Answer from sepp2k on reddit.com
🌐
GeeksforGeeks
geeksforgeeks.org › java › array-vs-arraylist-in-java
Array vs ArrayList in Java - GeeksforGeeks
June 5, 2026 - An array has a fixed size, while ArrayList is dynamic and part of the Java Collections Framework, offering more built-in methods for easy data manipulation.
🌐
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.
🌐
Ruby-Doc.org
ruby-doc.org › home › difference between array and arraylist in java – the ultimate guide
Difference Between Array and ArrayList in Java - The Ultimate Guide - Ruby-Doc.org
April 10, 2026 - Syntax examples: javaCopyEditint[] arr = new int[5]; String[] names = {"Alice", "Bob", "Carol"}; An ArrayList is part of the Java Collections Framework (java.util) and implements the List interface.
🌐
Reddit
reddit.com › r/learnprogramming › java: is arraylist better than arrays?
r/learnprogramming on Reddit: Java: Is Arraylist better than Arrays?
June 23, 2024 -

I've been programming in Java for 10 months now (as a subject in school) and i was always curious whats the biggest difference between Areays and Arraylist. I know that if i had an Arraylist named 'list' and i wrote System.out.print(list) it will print all the things that the list contains. Something that Arrays can't do that easily. But whats the actually biggest difference?

🌐
Codecademy
codecademy.com › learn › learn-java › modules › learn-java-arrays-and-arraylists › cheatsheet
Learn Java: Arrays and ArrayLists Cheatsheet | Codecademy
In Java, an ArrayList is used to represent a dynamic list. 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.
🌐
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
For example, int[] numbers are valid but ArrayList of int is not valid. how do you deal with this problem? Suppose you want to store int primitives into ArrayList then how do you that?
🌐
Baeldung
baeldung.com › home › java › java array › array vs. list performance in java
Array vs. List Performance in Java | Baeldung
March 7, 2025 - The results show that the average time to create an array (202.909 ns/op) is much faster than the average time to create an ArrayList (231.565 ns/op). Let’s compare the performance of adding items in an array and an ArrayList:
🌐
Scaler
scaler.com › home › topics › difference between array and arraylist
Difference Between Array and Arraylist - Scaler Topics
August 14, 2023 - Similar to arrays, it is required to specify the data type of elements in an ArrayList and also while Instantiation of the ArrayList we need not to mention the size of the ArrayList like in the arrays we have to mention the size of the arrays during the instantiation process. This is the structure of ArrayList in java. We have mentioned the Initial Capacity of the ArrayList i.e 8 and we are inserting elements in the elements in a continuous manner. ... Typename: In the type name we specify what kind of data value ArrayList will store. For example String, Integer, etc In the case ArrayList.
Find elsewhere
🌐
Blogger
javarevisited.blogspot.com › 2016 › 01 › 9-difference-between-array-vs-arraylist-in-java.html
Javarevisited: Difference between a List and Array in Java? ArrayList vs Array Example
For example, int[] numbers are valid but ArrayList of int is not valid. how do you deal with this problem? Suppose you want to store int primitives into ArrayList then how do you that?
🌐
Medium
medium.com › @AlexanderObregon › java-arrays-and-arraylists-a-comparative-look-bcbc97b32a1e
Java Arrays vs ArrayLists Guide | Medium
November 18, 2023 - While Java provides utility classes like Arrays in java.util for common operations, these are not as extensive or integrated as those available for ArrayLists. Java supports multidimensional arrays, which are arrays of arrays. These are particularly useful in scenarios where data is naturally structured in multiple dimensions, like a matrix. For example, a 2D array can be declared and initialized as follows:
🌐
Java67
java67.com › 2012 › 12 › difference-between-array-vs-arraylist-java.html
Difference between Array vs ArrayList in Java | Java67
6) One more difference on Array vs ArrayList is that you can create an instance of ArrayList without specifying size, Java will create Array List with default size but it's mandatory to provide the size of Array while creating either directly ...
🌐
Baeldung
baeldung.com › home › java › java list › list vs. arraylist in java
List vs. ArrayList in Java | Baeldung
December 9, 2025 - When we want to convert an array into a List quickly, we can use Arrays.asList(). This method wraps the array into a fixed-size List backed by the original array. We can read and update elements through the list, but we cannot change its size (no adding or removing). Next, let’s understand its usage through an example:
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 › lets-do-it-pl › arrays-vs-arraylist-99b3d845e404
Arrays vs ArrayList. With explanation and comparison in Java | by M. Hamdi Ozdil | Let’s Do It PL | Medium
April 12, 2021 - The answer is: “ArrayLists”. Because ArrayLists have infinite capacity. Cool, isn’t it? Let’s solve the same problem with ArrayList. ArrayList<Integer> listOfSales = new ArrayList<>();
🌐
DataFlair
data-flair.training › blogs › array-vs-arraylist-java
Array vs ArrayList in Java Learn with Examples - DataFlair
May 19, 2018 - An array on the other hand is a composite data type of java. We cannot call methods with an array except length. 3. Performance: Since ArrayList implicitly uses Array, we might think they perform at the same speed. It is partially correct. ArrayList performs all the basic functionalities with the same speed as an Array. But ArrayList performs various extra functions that perform slowly as it affects the CPU memory. For example, if we resize the ArrayList, it would copy the content of the array to another array then resize it.
🌐
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!

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.)

🌐
Medium
medium.com › @epengfei › array-vs-arraylist-in-java-a6328cd3c6a9
Array vs ArrayList in Java. Array and ArrayList are two commonly… | by Fei Peng | Medium
November 16, 2023 - This is because the List is backed by the original planets array, and any modifications made to the array will be reflected in the List. ... To create an array from an existing ArrayList in Java, you can use the toArray() method. Here’s an example of how to use it:
🌐
Blogger
javahungry.blogspot.com › 2015 › 03 › difference-between-array-and-arraylist-in-java-example.html
8 Difference between Array and ArrayList in Java with Example | Java Hungry
2. Duplicate elements : Both array and arraylist can contain duplicate elements. 3. Null Values : Both can store null values and uses index to refer to their elements. 4. Unordered : Both does not guarantee ordered elements. Recap : Difference between Array and ArrayList in Java