AP Computer Science a Flashcards: Implementing Arraylist Algorithms

Study Implementing Arraylist Algorithms 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

Implementing Arraylist Algorithms

0 mastered0 still learning

0% Complete

QUESTION
1/ 55

What method swaps two elements at specified positions in an ArrayList?

Tap card or press Space to flip

ANSWER

Collections.swap(list, i, j). Exchanges elements at positions i and j using Collections utility.

How well did you know it?

Card 1 / 55

What this deck covers

This deck focuses on Implementing Arraylist Algorithms, 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: What method swaps two elements at specified positions in an ArrayList?

Answer: Collections.swap(list, i, j). Exchanges elements at positions i and j using Collections utility.

Flashcard 2: What method adds an element to an ArrayList at a specified index?

Answer: add(index, element). Inserts element at specified position, shifting subsequent elements right.

Flashcard 3: What method adds all elements of one ArrayList to another?

Answer: addAll(Collection<? extends E> c). Appends all elements from another collection to current ArrayList.

Flashcard 4: How do you reverse the elements in an ArrayList?

Answer: Collections.reverse(list). Uses Collections utility to reverse element order in place.

Flashcard 5: How do you find the size of an ArrayList?

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

Flashcard 6: What method retrieves an element from an ArrayList by index?

Answer: get(index). Directly accesses element at specified position without modification.

Flashcard 7: How do you find the size of an ArrayList?

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

Flashcard 8: Which method replaces an element at a specified index in an ArrayList?

Answer: set(index, element). Replaces existing element at specified position with new element.

Flashcard 9: How do you convert an ArrayList to an array of Strings?

Answer: list.toArray(new String[0]). Converts to String array with proper type safety using parameterized method.

Flashcard 10: Find the index of the first occurrence of an element in an ArrayList.

Answer: indexOf(element). Returns position of first matching element, or -1 if not found.

Flashcard 11: Identify the method that returns an iterator over the elements in an ArrayList.

Answer: iterator(). Provides forward-only traversal through ArrayList elements.

Flashcard 12: Find the time complexity of removing an element by index from an ArrayList.

Answer: O(n). Linear time due to shifting all subsequent elements left.

Flashcard 13: What method returns an array containing all elements of an ArrayList?

Answer: toArray(). Converts ArrayList to standard array containing all elements.

Flashcard 14: Identify the import statement for using ArrayList in Java.

Answer: import java.util.ArrayList;. Required import statement to use ArrayList class in Java programs.

Flashcard 15: Identify the method to sort elements in an ArrayList using a comparator.

Answer: sort(Comparator<? super E> c). Sorts using custom comparison logic defined by Comparator implementation.

Flashcard 16: Identify the method to sort elements in an ArrayList using a comparator.

Answer: sort(Comparator<? super E> c). Sorts using custom comparison logic defined by Comparator implementation.

Flashcard 17: Identify the method to shuffle elements in an ArrayList.

Answer: Collections.shuffle(list). Randomly reorders elements using Collections utility method.

Flashcard 18: What is the time complexity of adding an element at the end of an ArrayList?

Answer: O(1) on average. Constant time unless internal array needs resizing (rare case).

Flashcard 19: Which method checks if an ArrayList is empty?

Answer: isEmpty(). Returns true if ArrayList contains no elements (size is zero).

Flashcard 20: Identify the method to clear all elements in an ArrayList.

Answer: clear(). Removes all elements from the ArrayList, making it empty.

Flashcard 21: How do you create an ArrayList of Strings named 'list'?

Answer: ArrayList list = new ArrayList<>();. Creates new ArrayList with String generic type using diamond operator.

Flashcard 22: Which method removes an element from an ArrayList by index?

Answer: remove(index). Removes element at specified position, shifting subsequent elements left.

Flashcard 23: What method retrieves an element from an ArrayList by index?

Answer: get(index). Directly accesses element at specified position without modification.

Flashcard 24: Which method removes an element from an ArrayList by index?

Answer: remove(index). Removes element at specified position, shifting subsequent elements left.

Flashcard 25: Which method returns the last index of a specified element in an ArrayList?

Answer: lastIndexOf(element). Finds rightmost position of element, or -1 if not found.

Flashcard 26: Which method checks if an ArrayList is empty?

Answer: isEmpty(). Returns true if ArrayList contains no elements (size is zero).

Flashcard 27: What method returns an array containing all elements of an ArrayList?

Answer: toArray(). Converts ArrayList to standard array containing all elements.

Flashcard 28: Identify the method to shuffle elements in an ArrayList.

Answer: Collections.shuffle(list). Randomly reorders elements using Collections utility method.

Flashcard 29: Find the time complexity of removing an element by index from an ArrayList.

Answer: O(n). Linear time due to shifting all subsequent elements left.

Flashcard 30: What method adds all elements of one ArrayList to another?

Answer: addAll(Collection<? extends E> c). Appends all elements from another collection to current ArrayList.

Flashcard 31: Which method replaces an element at a specified index in an ArrayList?

Answer: set(index, element). Replaces existing element at specified position with new element.

Flashcard 32: How do you reverse the elements in an ArrayList?

Answer: Collections.reverse(list). Uses Collections utility to reverse element order in place.

Flashcard 33: Identify the method to sort elements in an ArrayList.

Answer: Collections.sort(list). Uses Collections utility class to sort elements in ascending order.

Flashcard 34: Identify the method that returns an iterator over the elements in an ArrayList.

Answer: iterator(). Provides forward-only traversal through ArrayList elements.

Flashcard 35: How do you create an ArrayList of Strings named 'list'?

Answer: ArrayList list = new ArrayList<>();. Creates new ArrayList with String generic type using diamond operator.

Flashcard 36: What method adds an element to an ArrayList at a specified index?

Answer: add(index, element). Inserts element at specified position, shifting subsequent elements right.

Flashcard 37: What method copies elements from one ArrayList to another?

Answer: Collections.copy(dest, src). Copies elements from source to destination ArrayList using Collections.

Flashcard 38: What method checks if an ArrayList contains a specific element?

Answer: contains(element). Returns true if ArrayList contains at least one instance of element.

Flashcard 39: How do you convert an ArrayList to an array of Strings?

Answer: list.toArray(new String[0]). Converts to String array with proper type safety using parameterized method.

Flashcard 40: What method checks if an ArrayList contains a specific element?

Answer: contains(element). Returns true if ArrayList contains at least one instance of element.

Flashcard 41: Identify the method to add an element to the end of an ArrayList.

Answer: add(element). Appends element to the end of the ArrayList.

Flashcard 42: Identify the method to replace all elements in an ArrayList with a specified value.

Answer: Collections.fill(list, value). Uses Collections utility to replace all elements with single value.

Flashcard 43: What is the time complexity of accessing an element by index in an ArrayList?

Answer: O(1). Constant time since ArrayList uses array indexing internally.

Flashcard 44: Identify the method to sort elements in an ArrayList.

Answer: Collections.sort(list). Uses Collections utility class to sort elements in ascending order.

Flashcard 45: What method copies elements from one ArrayList to another?

Answer: Collections.copy(dest, src). Copies elements from source to destination ArrayList using Collections.

Flashcard 46: What method removes the first occurrence of a specified element in an ArrayList?

Answer: remove(Object o). Removes first matching element based on equals() comparison.

Flashcard 47: What method swaps two elements at specified positions in an ArrayList?

Answer: Collections.swap(list, i, j). Exchanges elements at positions i and j using Collections utility.

Flashcard 48: Find the index of the first occurrence of an element in an ArrayList.

Answer: indexOf(element). Returns position of first matching element, or -1 if not found.

Flashcard 49: What method returns a sublist of an ArrayList from index 'from' to 'to'?

Answer: subList(int from, int to). Returns view of portion between indices (exclusive of 'to' index).

Flashcard 50: What method returns a sublist of an ArrayList from index 'from' to 'to'?

Answer: subList(int from, int to). Returns view of portion between indices (exclusive of 'to' index).

Flashcard 51: What method removes the first occurrence of a specified element in an ArrayList?

Answer: remove(Object o). Removes first matching element based on equals() comparison.

Flashcard 52: Identify the method to clear all elements in an ArrayList.

Answer: clear(). Removes all elements from the ArrayList, making it empty.

Flashcard 53: Which method returns the last index of a specified element in an ArrayList?

Answer: lastIndexOf(element). Finds rightmost position of element, or -1 if not found.

Flashcard 54: Identify the method to replace all elements in an ArrayList with a specified value.

Answer: Collections.fill(list, value). Uses Collections utility to replace all elements with single value.

Flashcard 55: Identify the import statement for using ArrayList in Java.

Answer: import java.util.ArrayList;. Required import statement to use ArrayList class in Java programs.