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()
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()
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.
What is required to remove an object from any position in an ArrayList without causing an IndexOutOfBoundsException?
A valid object reference to be removed
The list must not be empty and the index must be valid within the list's bounds
All items in the list must be of the same type of memory
Size of the list and sufficient memory space
Considering Object-Oriented Programming principles, which scenario illustrates the advantage of using composition over inheritance to build maintainable code structures?
Designing Player characters holding weapon objects swappable based on gameplay decisions
Implementing a sort algorithm utilizing generics efficiently to handle multiple data types
Extending basic UI component class with additional features for specialized user interfaces
Creating Animal class with categories that require exact behavior traits specific to each category
What compromise must be considered when choosing between using an ArrayList versus a LinkedList for handling large numbers of elements with frequent insertions at various positions?
LinkedList might have lower performance for getting or setting elements because of the need to traverse elements sequentially.
ArrayList automatically adjusts storage allocation efficiently during insertion processes.
ArrayList often requires less code complexity due to easier implementation methods.
LinkedLists can only store primitive types, thus limiting flexibility compared to ArrayLists.

How are we doing?
Give us your feedback and let us know how we can improve
What does the following code do?
public static boolean codeBlock(ArrayList
Checks for duplicate elements in an ArrayList
Finds the double of the sum of all elements in an ArrayList
Checks if any element in an ArrayList equals its corresponding index value
Finds the number of unique elements in an ArrayList
Why might a developer choose to implement binary search on an sorted ArrayList
rather than linear search?
Linear search works only if every element is unique within the ArrayList
.
Binary search can be applied regardless of whether the list is sorted or not.
Linear search provides more accurate results when searching for strings instead of numbers.
Binary search has lower time complexity on sorted lists than linear search does.
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