Implementing ArrayList Algorithms - AP Computer Science A
Card 1 of 30
How do you reverse the elements in an ArrayList?
How do you reverse the elements in an ArrayList?
Tap to reveal answer
Collections.reverse(list). Uses Collections utility to reverse element order in place.
Collections.reverse(list). Uses Collections utility to reverse element order in place.
← Didn't Know|Knew It →
What method swaps two elements at specified positions in an ArrayList?
What method swaps two elements at specified positions in an ArrayList?
Tap to reveal answer
Collections.swap(list, i, j). Exchanges elements at positions i and j using Collections utility.
Collections.swap(list, i, j). Exchanges elements at positions i and j using Collections utility.
← Didn't Know|Knew It →
Identify the method to replace all elements in an ArrayList with a specified value.
Identify the method to replace all elements in an ArrayList with a specified value.
Tap to reveal answer
Collections.fill(list, value). Uses Collections utility to replace all elements with single value.
Collections.fill(list, value). Uses Collections utility to replace all elements with single value.
← Didn't Know|Knew It →
What method removes the first occurrence of a specified element in an ArrayList?
What method removes the first occurrence of a specified element in an ArrayList?
Tap to reveal answer
remove(Object o). Removes first matching element based on equals() comparison.
remove(Object o). Removes first matching element based on equals() comparison.
← Didn't Know|Knew It →
Identify the method that returns an iterator over the elements in an ArrayList.
Identify the method that returns an iterator over the elements in an ArrayList.
Tap to reveal answer
iterator(). Provides forward-only traversal through ArrayList elements.
iterator(). Provides forward-only traversal through ArrayList elements.
← Didn't Know|Knew It →
What method returns a sublist of an ArrayList from index 'from' to 'to'?
What method returns a sublist of an ArrayList from index 'from' to 'to'?
Tap to reveal answer
subList(int from, int to). Returns view of portion between indices (exclusive of 'to' index).
subList(int from, int to). Returns view of portion between indices (exclusive of 'to' index).
← Didn't Know|Knew It →
What method adds all elements of one ArrayList to another?
What method adds all elements of one ArrayList to another?
Tap to reveal answer
addAll(Collection<? extends E> c). Appends all elements from another collection to current ArrayList.
addAll(Collection<? extends E> c). Appends all elements from another collection to current ArrayList.
← Didn't Know|Knew It →
Identify the method to clear all elements in an ArrayList.
Identify the method to clear all elements in an ArrayList.
Tap to reveal answer
clear(). Removes all elements from the ArrayList, making it empty.
clear(). Removes all elements from the ArrayList, making it empty.
← Didn't Know|Knew It →
Which method replaces an element at a specified index in an ArrayList?
Which method replaces an element at a specified index in an ArrayList?
Tap to reveal answer
set(index, element). Replaces existing element at specified position with new element.
set(index, element). Replaces existing element at specified position with new element.
← Didn't Know|Knew It →
Identify the method to sort elements in an ArrayList using a comparator.
Identify the method to sort elements in an ArrayList using a comparator.
Tap to reveal answer
sort(Comparator<? super E> c). Sorts using custom comparison logic defined by Comparator implementation.
sort(Comparator<? super E> c). Sorts using custom comparison logic defined by Comparator implementation.
← Didn't Know|Knew It →
How do you convert an ArrayList to an array of Strings?
How do you convert an ArrayList to an array of Strings?
Tap to reveal answer
list.toArray(new String[0]). Converts to String array with proper type safety using parameterized method.
list.toArray(new String[0]). Converts to String array with proper type safety using parameterized method.
← Didn't Know|Knew It →
What method copies elements from one ArrayList to another?
What method copies elements from one ArrayList to another?
Tap to reveal answer
Collections.copy(dest, src). Copies elements from source to destination ArrayList using Collections.
Collections.copy(dest, src). Copies elements from source to destination ArrayList using Collections.
← Didn't Know|Knew It →
Identify the method to shuffle elements in an ArrayList.
Identify the method to shuffle elements in an ArrayList.
Tap to reveal answer
Collections.shuffle(list). Randomly reorders elements using Collections utility method.
Collections.shuffle(list). Randomly reorders elements using Collections utility method.
← Didn't Know|Knew It →
How do you find the size of an ArrayList?
How do you find the size of an ArrayList?
Tap to reveal answer
size(). Returns current number of elements stored in the ArrayList.
size(). Returns current number of elements stored in the ArrayList.
← Didn't Know|Knew It →
What method retrieves an element from an ArrayList by index?
What method retrieves an element from an ArrayList by index?
Tap to reveal answer
get(index). Directly accesses element at specified position without modification.
get(index). Directly accesses element at specified position without modification.
← Didn't Know|Knew It →
What method copies elements from one ArrayList to another?
What method copies elements from one ArrayList to another?
Tap to reveal answer
Collections.copy(dest, src). Copies elements from source to destination ArrayList using Collections.
Collections.copy(dest, src). Copies elements from source to destination ArrayList using Collections.
← Didn't Know|Knew It →
Find the time complexity of removing an element by index from an ArrayList.
Find the time complexity of removing an element by index from an ArrayList.
Tap to reveal answer
O(n). Linear time due to shifting all subsequent elements left.
O(n). Linear time due to shifting all subsequent elements left.
← Didn't Know|Knew It →
What is the time complexity of adding an element at the end of an ArrayList?
What is the time complexity of adding an element at the end of an ArrayList?
Tap to reveal answer
O(1) on average. Constant time unless internal array needs resizing (rare case).
O(1) on average. Constant time unless internal array needs resizing (rare case).
← Didn't Know|Knew It →
What method retrieves an element from an ArrayList by index?
What method retrieves an element from an ArrayList by index?
Tap to reveal answer
get(index). Directly accesses element at specified position without modification.
get(index). Directly accesses element at specified position without modification.
← Didn't Know|Knew It →
What method removes the first occurrence of a specified element in an ArrayList?
What method removes the first occurrence of a specified element in an ArrayList?
Tap to reveal answer
remove(Object o). Removes first matching element based on equals() comparison.
remove(Object o). Removes first matching element based on equals() comparison.
← Didn't Know|Knew It →
Identify the method to clear all elements in an ArrayList.
Identify the method to clear all elements in an ArrayList.
Tap to reveal answer
clear(). Removes all elements from the ArrayList, making it empty.
clear(). Removes all elements from the ArrayList, making it empty.
← Didn't Know|Knew It →
What method returns an array containing all elements of an ArrayList?
What method returns an array containing all elements of an ArrayList?
Tap to reveal answer
toArray(). Converts ArrayList to standard array containing all elements.
toArray(). Converts ArrayList to standard array containing all elements.
← Didn't Know|Knew It →
Which method returns the last index of a specified element in an ArrayList?
Which method returns the last index of a specified element in an ArrayList?
Tap to reveal answer
lastIndexOf(element). Finds rightmost position of element, or -1 if not found.
lastIndexOf(element). Finds rightmost position of element, or -1 if not found.
← Didn't Know|Knew It →
What is the time complexity of accessing an element by index in an ArrayList?
What is the time complexity of accessing an element by index in an ArrayList?
Tap to reveal answer
O(1). Constant time since ArrayList uses array indexing internally.
O(1). Constant time since ArrayList uses array indexing internally.
← Didn't Know|Knew It →
Identify the method to replace all elements in an ArrayList with a specified value.
Identify the method to replace all elements in an ArrayList with a specified value.
Tap to reveal answer
Collections.fill(list, value). Uses Collections utility to replace all elements with single value.
Collections.fill(list, value). Uses Collections utility to replace all elements with single value.
← Didn't Know|Knew It →
Identify the method to sort elements in an ArrayList.
Identify the method to sort elements in an ArrayList.
Tap to reveal answer
Collections.sort(list). Uses Collections utility class to sort elements in ascending order.
Collections.sort(list). Uses Collections utility class to sort elements in ascending order.
← Didn't Know|Knew It →
How do you reverse the elements in an ArrayList?
How do you reverse the elements in an ArrayList?
Tap to reveal answer
Collections.reverse(list). Uses Collections utility to reverse element order in place.
Collections.reverse(list). Uses Collections utility to reverse element order in place.
← Didn't Know|Knew It →
What method swaps two elements at specified positions in an ArrayList?
What method swaps two elements at specified positions in an ArrayList?
Tap to reveal answer
Collections.swap(list, i, j). Exchanges elements at positions i and j using Collections utility.
Collections.swap(list, i, j). Exchanges elements at positions i and j using Collections utility.
← Didn't Know|Knew It →
Identify the method to shuffle elements in an ArrayList.
Identify the method to shuffle elements in an ArrayList.
Tap to reveal answer
Collections.shuffle(list). Randomly reorders elements using Collections utility method.
Collections.shuffle(list). Randomly reorders elements using Collections utility method.
← Didn't Know|Knew It →
What method returns a sublist of an ArrayList from index 'from' to 'to'?
What method returns a sublist of an ArrayList from index 'from' to 'to'?
Tap to reveal answer
subList(int from, int to). Returns view of portion between indices (exclusive of 'to' index).
subList(int from, int to). Returns view of portion between indices (exclusive of 'to' index).
← Didn't Know|Knew It →