ArrayList Methods - AP Computer Science A
Card 1 of 30
Identify the method that removes the first occurrence of a specified element in an ArrayList.
Identify the method that removes the first occurrence of a specified element in an ArrayList.
Tap to reveal answer
remove(Object o). Searches and removes by value, not index.
remove(Object o). Searches and removes by value, not index.
← Didn't Know|Knew It →
What is the purpose of the ArrayList add method?
What is the purpose of the ArrayList add method?
Tap to reveal answer
Adds an element to the ArrayList. Inserts elements at the end or specified position.
Adds an element to the ArrayList. Inserts elements at the end or specified position.
← Didn't Know|Knew It →
Identify the method that removes an element at a specified index in an ArrayList.
Identify the method that removes an element at a specified index in an ArrayList.
Tap to reveal answer
remove(int index). Removes by index and returns the removed element.
remove(int index). Removes by index and returns the removed element.
← Didn't Know|Knew It →
What does the ArrayList get method return?
What does the ArrayList get method return?
Tap to reveal answer
Returns the element at the specified index. Accesses elements without modifying the ArrayList.
Returns the element at the specified index. Accesses elements without modifying the ArrayList.
← Didn't Know|Knew It →
Find the method to clear all elements from an ArrayList.
Find the method to clear all elements from an ArrayList.
Tap to reveal answer
clear(). Removes all elements, making the list empty.
clear(). Removes all elements, making the list empty.
← Didn't Know|Knew It →
What does the ArrayList isEmpty method check?
What does the ArrayList isEmpty method check?
Tap to reveal answer
Checks if the ArrayList is empty. Returns true if size equals zero.
Checks if the ArrayList is empty. Returns true if size equals zero.
← Didn't Know|Knew It →
Which method returns the number of elements in an ArrayList?
Which method returns the number of elements in an ArrayList?
Tap to reveal answer
size(). Returns the current number of stored elements.
size(). Returns the current number of stored elements.
← Didn't Know|Knew It →
Identify the method to check if an ArrayList contains a specific element.
Identify the method to check if an ArrayList contains a specific element.
Tap to reveal answer
contains(Object o). Returns true if element exists in the list.
contains(Object o). Returns true if element exists in the list.
← Didn't Know|Knew It →
What does the ArrayList indexOf method return?
What does the ArrayList indexOf method return?
Tap to reveal answer
Returns index of first occurrence of an element. Returns -1 if element is not found.
Returns index of first occurrence of an element. Returns -1 if element is not found.
← Didn't Know|Knew It →
Which method returns the index of the last occurrence of an element in an ArrayList?
Which method returns the index of the last occurrence of an element in an ArrayList?
Tap to reveal answer
lastIndexOf(Object o). Searches backwards from the end of the list.
lastIndexOf(Object o). Searches backwards from the end of the list.
← Didn't Know|Knew It →
Find the method to add an element at a specific position in an ArrayList.
Find the method to add an element at a specific position in an ArrayList.
Tap to reveal answer
add(int index, E element). Inserts element and shifts existing elements right.
add(int index, E element). Inserts element and shifts existing elements right.
← Didn't Know|Knew It →
What is the return type of the ArrayList remove method?
What is the return type of the ArrayList remove method?
Tap to reveal answer
Returns the element that was removed. Returns the element that was at the index.
Returns the element that was removed. Returns the element that was at the index.
← Didn't Know|Knew It →
Which method returns a shallow copy of an ArrayList?
Which method returns a shallow copy of an ArrayList?
Tap to reveal answer
clone(). Creates independent copy with same elements.
clone(). Creates independent copy with same elements.
← Didn't Know|Knew It →
In which scenario does the ArrayList get method throw an exception?
In which scenario does the ArrayList get method throw an exception?
Tap to reveal answer
Throws IndexOutOfBoundsException if index is out of range. When index is negative or >= size().
Throws IndexOutOfBoundsException if index is out of range. When index is negative or >= size().
← Didn't Know|Knew It →
What is the purpose of the toArray method in ArrayList?
What is the purpose of the toArray method in ArrayList?
Tap to reveal answer
Converts the ArrayList to an array. Creates Object array containing list elements.
Converts the ArrayList to an array. Creates Object array containing list elements.
← Didn't Know|Knew It →
Identify the method to remove all elements from an ArrayList that are in a specified collection.
Identify the method to remove all elements from an ArrayList that are in a specified collection.
Tap to reveal answer
removeAll(Collection<?> c). Removes elements that exist in both collections.
removeAll(Collection<?> c). Removes elements that exist in both collections.
← Didn't Know|Knew It →
Which method retains only the elements in an ArrayList that are in a specified collection?
Which method retains only the elements in an ArrayList that are in a specified collection?
Tap to reveal answer
retainAll(Collection<?> c). Keeps only common elements between collections.
retainAll(Collection<?> c). Keeps only common elements between collections.
← Didn't Know|Knew It →
Which method in ArrayList returns an iterator over the elements?
Which method in ArrayList returns an iterator over the elements?
Tap to reveal answer
iterator(). Enables traversal through enhanced for loops.
iterator(). Enables traversal through enhanced for loops.
← Didn't Know|Knew It →
Which method sorts the elements of an ArrayList based on a specified comparator?
Which method sorts the elements of an ArrayList based on a specified comparator?
Tap to reveal answer
sort(Comparator<? super E> c). Orders elements according to comparison logic.
sort(Comparator<? super E> c). Orders elements according to comparison logic.
← Didn't Know|Knew It →
What is the boolean return type of the remove method used with an object in ArrayList?
What is the boolean return type of the remove method used with an object in ArrayList?
Tap to reveal answer
True if the element is successfully removed. Returns false if element was not found.
True if the element is successfully removed. Returns false if element was not found.
← Didn't Know|Knew It →
Which method in ArrayList appends all elements in a specified collection?
Which method in ArrayList appends all elements in a specified collection?
Tap to reveal answer
addAll(Collection<? extends E> c). Adds all elements to the end sequentially.
addAll(Collection<? extends E> c). Adds all elements to the end sequentially.
← Didn't Know|Knew It →
Identify the method that inserts all elements of a collection into an ArrayList at a specified position.
Identify the method that inserts all elements of a collection into an ArrayList at a specified position.
Tap to reveal answer
addAll(int index, Collection<? extends E> c). Shifts existing elements to accommodate new ones.
addAll(int index, Collection<? extends E> c). Shifts existing elements to accommodate new ones.
← Didn't Know|Knew It →
What does the subList method in ArrayList return?
What does the subList method in ArrayList return?
Tap to reveal answer
Returns a view of a portion of the list. Creates sublist that reflects changes to original.
Returns a view of a portion of the list. Creates sublist that reflects changes to original.
← Didn't Know|Knew It →
Find the method that checks for equality between an ArrayList and another object.
Find the method that checks for equality between an ArrayList and another object.
Tap to reveal answer
equals(Object o). Compares element-by-element for structural equality.
equals(Object o). Compares element-by-element for structural equality.
← Didn't Know|Knew It →
What does the ArrayList hashCode method return?
What does the ArrayList hashCode method return?
Tap to reveal answer
Returns hash code value for the list. Computed from elements for hashing collections.
Returns hash code value for the list. Computed from elements for hashing collections.
← Didn't Know|Knew It →
What is the consequence of modifying an ArrayList while iterating over it?
What is the consequence of modifying an ArrayList while iterating over it?
Tap to reveal answer
Throws ConcurrentModificationException. Prevents corruption from simultaneous modifications.
Throws ConcurrentModificationException. Prevents corruption from simultaneous modifications.
← Didn't Know|Knew It →
What exception does the set method throw if the index is out of range?
What exception does the set method throw if the index is out of range?
Tap to reveal answer
IndexOutOfBoundsException. Thrown when index < 0 or >= size().
IndexOutOfBoundsException. Thrown when index < 0 or >= size().
← Didn't Know|Knew It →
What does the toString method return for an ArrayList?
What does the toString method return for an ArrayList?
Tap to reveal answer
String representation of the list. Shows elements in bracket-separated format.
String representation of the list. Shows elements in bracket-separated format.
← Didn't Know|Knew It →
Find the method that checks if two ArrayLists are equal.
Find the method that checks if two ArrayLists are equal.
Tap to reveal answer
equals(Object o). Compares element-by-element for structural equality.
equals(Object o). Compares element-by-element for structural equality.
← Didn't Know|Knew It →
What is the boolean return type of the remove method used with an object in ArrayList?
What is the boolean return type of the remove method used with an object in ArrayList?
Tap to reveal answer
True if the element is successfully removed. Returns false if element was not found.
True if the element is successfully removed. Returns false if element was not found.
← Didn't Know|Knew It →