Practice: AP CSA ArrayList

Study material for practicing ArrayList concepts in AP Computer Science A exams.

WolfMia2·23 tarjetas·11 preguntas
APcomputer_scienceprogramming
0
Lo sé
1 / 23
0
Aprendiendo
Frente

What is an ArrayList?

Toca para voltear
Reverso

A resizable array implementation of the List interface in Java.

Toca para voltear
Lo sé
Aprendiendo

Quiz(11 preguntas)

Pregunta 1 de 11

1. Which of these is a method of ArrayList?

Términos en este 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]);

Preguntas en este set(11)

1. Which of these is a method of ArrayList?

A.add()
B.insert()
C.append()
D.push()

2. What does list.remove(index) do?

A.Removes all elements
B.Removes the element at the given index
C.Cleans the list
D.Returns the element

3. Which statement is true about ArrayLists?

A.They can hold primitive types
B.They cannot be resized
C.They allow duplicate values
D.They use fixed size

4. Which method checks if an ArrayList is empty?

A.isNull()
B.isEmpty()
C.size()
D.count()

5. What is the result of list.size() if it has 0 elements?

A.0
B.1
C.null
D.-1

6. When you call list.clear(), what happens?

A.Removes the last element
B.Removes all elements
C.Resizes to 0
D.Does nothing

7. How to find the index of a specific element?

A.list.indexOf(element)
B.list.getIndex(element)
C.list.find(element)
D.list.locate(element)

8. Which of the following is NOT a feature of ArrayLists?

A.Dynamic resizing
B.Holds primitives
C.Random access
D.Duplicates allowed

9. When would you prefer an ArrayList over an array?

A.When you need fixed size
B.When you need dynamic size
C.When performance is critical
D.When you only need primitives

10. Which method replaces an element at a specific index?

A.set()
B.replace()
C.update()
D.change()

11. True or false: ArrayLists can be synchronized.

A.True
B.False
C.Only in Java 8
D.Only for primitives

Sets relacionados

Crea tu propio set de estudio

Sube un PDF, pega tus notas o describe un tema – la IA genera tarjetas, quizzes y más en segundos.