Created: 2023-09-03 20:36
Status: #concept
Subject: Programming
Tags: Java java.util java.util.ArrayList java.util.Collection
java.util.List
It has the same methods as ArrayList, but it is statically-sized.
- it is the Java Interface for many subclasses including
ArrayList
. interface List<E>
List<String> strings = new ArrayList<>();
strings.add("string objects inside an arraylist object!");
All Known Implementing Classes:
ArrayList vs LinkedList
- adding to
LinkedList
is always fast because we save a Pointer to the last node.- It is slower in
ArrayList
because we need to reallocate memory and a size for the entire array list, plus the added element.
- It is slower in
- searching objects by index is faster with an
ArrayList
because we have the entire contiguous array.LinkedList
still needs to be traversed to find something in the middle.