What exactly is the point of using ArrayLists as oppose to regular lists?
It depends on what you mean by a "regular list".
If you mean
java.util.List
, then the point is that you cannot create an instance of thatList
type ... because it is aninterface
not aclass
.If you mean some other list class such as
java.util.LinkedList
... then you need to realize that each of the different list classes have their own behavioural / performance characteristics. For example:The
LinkedList
has fast insertion at the start of the list, but a slowget(int)
operation compared toArrayList
The
ArrayList
class has fastget
, and uses less memory on average1 than an equivalentLinkedList
.
And if you look at the code, before the methods names you have
<T> ArrayList<T>
. Is it because these areArrayLists
? And why the<T>
The <T>
denotes a type parameter of the generic merge
and append
methods. Read the Java Tutorial section on Generics ... and then you should be able to understand what this code is saying.
No, it is not "because these are ArrayLists
". You'd need to use the a generic type parameter for other list classes as well. The List
interface and all of the standard list classes are generic types.
1 - The space usage of ArrayList
is a bit rubbery, because it depends on the sequence of operations used to get to the list whose space usage you are measuring. But an optimal ArrayList
occupies much less space than a LinkedList
with the same elements. And this is true for typical use-cases as well.