Practice: AP CSA ArrayList
Study material for practicing ArrayList concepts in AP Computer Science A exams.
Quiz(11 domande)
1. Which of these is a method of ArrayList?
Termini in questo set(23)
What is an ArrayList?
A resizable array implementation of the List interface in Java.
Advantages of ArrayList over arrays?
- Dynamic resizing - Easier element manipulation - Built-in methods like add() and remove()
True or false: ArrayList can hold primitives.
False, because ArrayList can only hold objects. Use wrapper classes.
Difference between ArrayList and LinkedList?
ArrayList is indexed and supports fast random access; LinkedList allows fast insertions/deletions.
How do you declare an ArrayList?
ArrayList<Type> listName = new ArrayList<Type>();
What method adds an element to ArrayList?
Use the add() method: list.add(element);
Fill in the blank: ArrayLists are part of the _____ framework.
Collections
How to access the first element of an ArrayList?
Use list.get(0);
What does list.size() return?
The number of elements currently in the ArrayList.
True or false: ArrayLists can contain duplicate elements.
True, because ArrayLists allow duplicates.
What does the clear() method do?
Removes all elements from the ArrayList.
How to remove an element at index 2?
Use: list.remove(2);
Explain how to resize an ArrayList.
ArrayLists automatically resize when the capacity is exceeded; new arrays are created internally.
What is the initial capacity of an ArrayList?
The default initial capacity is 10.
When would you use an ArrayList?
When you need dynamic sizing and easy data manipulation.
What happens when you add an element beyond the current size?
The ArrayList automatically resizes to accommodate the new element.
How can you check if an ArrayList is empty?
Use list.isEmpty(); returns true if empty.
Difference between get() and set() methods?
get() retrieves an element; set() replaces an element at a specified index.
What will list.indexOf(element) return?
It returns the index of the first occurrence of the element, or -1 if not found.
How to create an ArrayList of Strings?
ArrayList<String> stringList = new ArrayList<>();
True or false: You can store null in an ArrayList.
True, because ArrayLists can contain null elements.
What is the difference between ArrayList and Vector?
Vector is synchronized, making it thread-safe, while ArrayList is not.
How to convert an ArrayList to an array?
Use list.toArray(new Type[0]);
Domande in questo set(11)
1. Which of these is a method of ArrayList?
2. What does list.remove(index) do?
3. Which statement is true about ArrayLists?
4. Which method checks if an ArrayList is empty?
5. What is the result of list.size() if it has 0 elements?
6. When you call list.clear(), what happens?
7. How to find the index of a specific element?
8. Which of the following is NOT a feature of ArrayLists?
9. When would you prefer an ArrayList over an array?
10. Which method replaces an element at a specific index?
11. True or false: ArrayLists can be synchronized.
Set correlati
Schleife Alltag Beispiel Begriffe
Abitur Datenbanken SELECT grob Prüfung
Wiederholung: Abitur Sortierverfahren
Abitur: Abitur Klassen und Objekte
Abitur Arrays
Abitur Rekursion
Debugging Schritt für Schritt
Bedingung Alltag Beispiel
Crea il tuo set di studio
Carica un PDF, incolla le tue note o descrivi un argomento – l'IA genera schede, quiz e altro in pochi secondi.

