AP Computer Science a Flashcards: Arraylist Methods

Study Arraylist Methods in AP Computer Science a with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science a

Arraylist Methods

0 mastered0 still learning

0% Complete

QUESTION
1/ 60

Identify the method that removes an element at a specified index in an ArrayList.

Tap card or press Space to flip

ANSWER

remove(int index). Removes by index and returns the removed element.

How well did you know it?

Card 1 / 60

What this deck covers

This deck focuses on Arraylist Methods, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science a.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: Identify the method that removes an element at a specified index in an ArrayList.

Answer: remove(int index). Removes by index and returns the removed element.

Flashcard 2: What exception does the set method throw if the index is out of range?

Answer: IndexOutOfBoundsException. Thrown when index < 0 or >= size().

Flashcard 3: Identify the method that removes the first occurrence of a specified element in an ArrayList.

Answer: remove(Object o). Searches and removes by value, not index.

Flashcard 4: What does the ArrayList get method return?

Answer: Returns the element at the specified index. Accesses elements without modifying the ArrayList.

Flashcard 5: Identify the method to check if an ArrayList contains a specific element.

Answer: contains(Object o). Returns true if element exists in the list.

Flashcard 6: What exception does the set method throw if the index is out of range?

Answer: IndexOutOfBoundsException. Thrown when index < 0 or >= size().

Flashcard 7: What is the return type of the ArrayList remove method?

Answer: Returns the element that was removed. Returns the element that was at the index.

Flashcard 8: Identify the method that inserts all elements of a collection into an ArrayList at a specified position.

Answer: addAll(int index, Collection<? extends E> c). Shifts existing elements to accommodate new ones.

Flashcard 9: What does the ArrayList hashCode method return?

Answer: Returns hash code value for the list. Computed from elements for hashing collections.

Flashcard 10: Which method returns the index of the last occurrence of an element in an ArrayList?

Answer: lastIndexOf(Object o). Searches backwards from the end of the list.

Flashcard 11: Find the method to clear all elements from an ArrayList.

Answer: clear(). Removes all elements, making the list empty.

Flashcard 12: What is the boolean return type of the remove method used with an object in ArrayList?

Answer: True if the element is successfully removed. Returns false if element was not found.

Flashcard 13: Identify the method to check if an ArrayList contains a specific element.

Answer: contains(Object o). Returns true if element exists in the list.

Flashcard 14: Identify the method that inserts all elements of a collection into an ArrayList at a specified position.

Answer: addAll(int index, Collection<? extends E> c). Shifts existing elements to accommodate new ones.

Flashcard 15: Which method in ArrayList appends all elements in a specified collection?

Answer: addAll(Collection<? extends E> c). Adds all elements to the end sequentially.

Flashcard 16: Which method retains only the elements in an ArrayList that are in a specified collection?

Answer: retainAll(Collection<?> c). Keeps only common elements between collections.

Flashcard 17: What is the consequence of modifying an ArrayList while iterating over it?

Answer: Throws ConcurrentModificationException. Prevents corruption from simultaneous modifications.

Flashcard 18: Identify the method that removes an element at a specified index in an ArrayList.

Answer: remove(int index). Removes by index and returns the removed element.

Flashcard 19: Find the method to clear all elements from an ArrayList.

Answer: clear(). Removes all elements, making the list empty.

Flashcard 20: What is the consequence of modifying an ArrayList while iterating over it?

Answer: Throws ConcurrentModificationException. Prevents corruption from simultaneous modifications.

Flashcard 21: What does the ArrayList isEmpty method check?

Answer: Checks if the ArrayList is empty. Returns true if size equals zero.

Flashcard 22: Which method in ArrayList returns an iterator over the elements?

Answer: iterator(). Enables traversal through enhanced for loops.

Flashcard 23: Which method in ArrayList returns an iterator over the elements?

Answer: iterator(). Enables traversal through enhanced for loops.

Flashcard 24: Which method returns the index of the last occurrence of an element in an ArrayList?

Answer: lastIndexOf(Object o). Searches backwards from the end of the list.

Flashcard 25: What does the toString method return for an ArrayList?

Answer: String representation of the list. Shows elements in bracket-separated format.

Flashcard 26: In which scenario does the ArrayList get method throw an exception?

Answer: Throws IndexOutOfBoundsException if index is out of range. When index is negative or >= size().

Flashcard 27: Which method replaces an element at a specified position in an ArrayList?

Answer: set(int index, E element). Replaces existing element and returns old value.

Flashcard 28: What is the purpose of the toArray method in ArrayList?

Answer: Converts the ArrayList to an array. Creates Object array containing list elements.

Flashcard 29: What does the ArrayList indexOf method return?

Answer: Returns index of first occurrence of an element. Returns -1 if element is not found.

Flashcard 30: What does the toString method return for an ArrayList?

Answer: String representation of the list. Shows elements in bracket-separated format.

Flashcard 31: What does the subList method in ArrayList return?

Answer: Returns a view of a portion of the list. Creates sublist that reflects changes to original.

Flashcard 32: What is the purpose of the toArray method in ArrayList?

Answer: Converts the ArrayList to an array. Creates Object array containing list elements.

Flashcard 33: What is the purpose of the ArrayList add method?

Answer: Adds an element to the ArrayList. Inserts elements at the end or specified position.

Flashcard 34: Find the method that checks if two ArrayLists are equal.

Answer: equals(Object o). Compares element-by-element for structural equality.

Flashcard 35: Which method returns a shallow copy of an ArrayList?

Answer: clone(). Creates independent copy with same elements.

Flashcard 36: Which method returns a shallow copy of an ArrayList?

Answer: clone(). Creates independent copy with same elements.

Flashcard 37: What is the boolean return type of the remove method used with an object in ArrayList?

Answer: True if the element is successfully removed. Returns false if element was not found.

Flashcard 38: What does the subList method in ArrayList return?

Answer: Returns a view of a portion of the list. Creates sublist that reflects changes to original.

Flashcard 39: What does the ArrayList isEmpty method check?

Answer: Checks if the ArrayList is empty. Returns true if size equals zero.

Flashcard 40: What does the ArrayList hashCode method return?

Answer: Returns hash code value for the list. Computed from elements for hashing collections.

Flashcard 41: What does the ArrayList get method return?

Answer: Returns the element at the specified index. Accesses elements without modifying the ArrayList.

Flashcard 42: Which method returns the number of elements in an ArrayList?

Answer: size(). Returns the current number of stored elements.

Flashcard 43: Find the method to add an element at a specific position in an ArrayList.

Answer: add(int index, E element). Inserts element and shifts existing elements right.

Flashcard 44: Identify the method to remove all elements from an ArrayList that are in a specified collection.

Answer: removeAll(Collection<?> c). Removes elements that exist in both collections.

Flashcard 45: Which method sorts the elements of an ArrayList based on a specified comparator?

Answer: sort(Comparator<? super E> c). Orders elements according to comparison logic.

Flashcard 46: Which method returns the number of elements in an ArrayList?

Answer: size(). Returns the current number of stored elements.

Flashcard 47: Which method sorts the elements of an ArrayList based on a specified comparator?

Answer: sort(Comparator<? super E> c). Orders elements according to comparison logic.

Flashcard 48: What is the return type of the ArrayList remove method?

Answer: Returns the element that was removed. Returns the element that was at the index.

Flashcard 49: Find the method that checks for equality between an ArrayList and another object.

Answer: equals(Object o). Compares element-by-element for structural equality.

Flashcard 50: Which method retains only the elements in an ArrayList that are in a specified collection?

Answer: retainAll(Collection<?> c). Keeps only common elements between collections.

Flashcard 51: What does the ArrayList indexOf method return?

Answer: Returns index of first occurrence of an element. Returns -1 if element is not found.

Flashcard 52: Identify the method that removes the first occurrence of a specified element in an ArrayList.

Answer: remove(Object o). Searches and removes by value, not index.

Flashcard 53: Find the method that checks for equality between an ArrayList and another object.

Answer: equals(Object o). Compares element-by-element for structural equality.

Flashcard 54: In which scenario does the ArrayList get method throw an exception?

Answer: Throws IndexOutOfBoundsException if index is out of range. When index is negative or >= size().

Flashcard 55: Which method replaces an element at a specified position in an ArrayList?

Answer: set(int index, E element). Replaces existing element and returns old value.

Flashcard 56: Identify the method to remove all elements from an ArrayList that are in a specified collection.

Answer: removeAll(Collection<?> c). Removes elements that exist in both collections.

Flashcard 57: Which method in ArrayList appends all elements in a specified collection?

Answer: addAll(Collection<? extends E> c). Adds all elements to the end sequentially.

Flashcard 58: What is the purpose of the ArrayList add method?

Answer: Adds an element to the ArrayList. Inserts elements at the end or specified position.

Flashcard 59: Find the method to add an element at a specific position in an ArrayList.

Answer: add(int index, E element). Inserts element and shifts existing elements right.

Flashcard 60: Find the method that checks if two ArrayLists are equal.

Answer: equals(Object o). Compares element-by-element for structural equality.