What is a List vs. an ArrayList? [duplicate]

What are the fundamental differences between the two objects? Is one more efficient? Does one have more methods?


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


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.


List is an interface; ArrayList is a class that implements the List interface.

Interfaces define the method signatures that are required, but say nothing about how they are implemented.

Classes that implement an interface promise to provide public implementations of methods with the identical signatures declared by the interface.


A List defines the interface that ArrayList uses, that allows it to implement methods that will allow all other classes that implement List to be used together or in a similar way. An ArrayList is always also a List, but an List isn't necessarily an ArrayList.

That is, ArrayList implements List (among a few other interfaces).