add(E e): Adds an element to the end of the list.
addAll(Collection<? extends E> c): Adds all elements from a collection to the end of the list.
set(int index, E element): Replaces an element at a specified index.
remove(int index): Removes an element at a specified index.
remove(Object o): Removes the first occurrence of a specified element.
size(): Returns the number of elements in the list.
lastIndexOf(Object o): Returns the index of the last occurrence of a specified element.
iterator(): Returns an iterator over the elements in the list.
listIterator(): Returns a list iterator over the elements in the list.
ArrayList Operations
- Add Elements
add(element obj): Adds an element to the end of the list. Used three times.
add(int index, element obj): Adds an element at a specified index.
add(0, element obj): Adds an element at the beginning of the list.
add(size(), element obj): Adds an element at the end of the list.
- Remove Elements
remove(0): Removes the first element from the list.
remove(size() - 1): Removes the last element from the list.
remove(int index): Removes the element at a specified index.
- Get Elements
get(int index): Retrieves the element at a specified index.
get(0): Retrieves the first element of the list.
get(size() - 1): Retrieves the last element of the list.
- Set Element
set(int index, element obj): Replaces the element at a specified index with a new element.
- Traversal Techniques
- For each loop: Iterates over the elements using a for-each loop.
- Iterator: Iterates over the elements using an iterator.
- ListIterator: Iterates over the elements using a list iterator.
LinkedList Operations
- Add Elements
add(element obj): Adds an element to the end of the list. Used three times.
add(int position, element obj): Adds an element at a specified position.
addFirst(element obj): Adds an element at the beginning of the list.
addLast(element obj): Adds an element at the end of the list.
- Remove Elements
removeFirst(): Removes the first element from the list.
removeLast(): Removes the last element from the list.
remove(int position): Removes the element at a specified position.
- Get Elements
get(int position): Retrieves the element at a specified position.
getFirst(): Retrieves the first element of the list.
getLast(): Retrieves the last element of the list.