ArrayList in AP Computer Science A
How do you determine the number of elements currently stored in an ArrayList named "myList"?
myList.size()
myList.capacity()
myList.count()
myList.length()
What does the following code do?
public static ArrayList
Puts all elements of an ArrayList into an array in reverse order
Puts all elements of an array into an ArrayList in the original order
Puts all elements of an array into an ArrayList in reverse order
Puts all elements of an ArrayList into an array in the original order
When should you use a while loop over a traditional for loop while working with an ArrayList?
When iterating over each element to apply a uniform operation.
When iterating through the list by index from start to finish.
When indexing elements at even positions only.
When you need to iterate until a certain condition changes, and the number of iterations isn't known beforehand.
Which method is commonly used to add an element to an ArrayList in Java?
put()
insert()
add()
append()
How would one efficiently append all elements from one ArrayList listA
into another listB
ensuring that no duplicates are added to listB
?
Implement nested loops comparing every pair between lists before adding non-duplicates.
Apply recursive backtracking method ensuring each addition maintains uniqueness.
Use an if-statement inside a for-each loop checking !listB.contains(element)
before appending.
Use 'listB.addAll(listA)' ignoring duplicate entries.
In order to replace every instance of 'apple' with 'orange' in an ArrayList
Call fruits.replaceAll('apple', 'orange');
Apply Collections.swap(fruits, fruits.indexOf('apple'), fruits.indexOf('orange'));
Use a for-loop to check each string with equals('apple') and set that index's value to 'orange'.
Use fruits.indexOf('apple') repeatedly until all instances are replaced with oranges.
Which method signature would correctly allow an algorithm that uses ArrayLists to handle exceptions when items are added incorrectly?
static int addItem(ArrayList
public boolean addItem(ArrayList
public void addItem(ArrayList
private void addItem(ArrayList

How are we doing?
Give us your feedback and let us know how we can improve
What code would replace "item" from position "index" in an existing ArrayList
records.swap(item, index);
records.update(index, item);
records.set(index, item);
records.replace(item, index);
What would be the best reason to use an ArrayList over an array when developing an algorithm?
ArrayLists can change size dynamically as needed.
ArrayLists have a fixed size that cannot change once initialized.
ArrayLists improve the speed of all search operations compared to arrays.
ArrayLists are more memory efficient than arrays with large datasets.
What is returned by the following code if the passed in ArrayList is [6, 5, 5, 2, 8]?
public static int codeBlock(ArrayList
8
6
2
5