1/37
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What is the main focus of Chapter 6?
Understanding Java’s list structures, especially the ArrayList class, and how to manage dynamic collections of objects.
What is a list in computer science?
An ordered collection of elements that can grow or shrink in size and allows duplicate items.
What is the ArrayList class in Java?
A resizable list implementation from java.util that stores objects in a dynamically sized array.
How do you import ArrayList in Java?
import java.util.ArrayList;
How do you declare an ArrayList of strings?
ArrayList
What does the
It specifies the element type using Java generics, ensuring type safety.
What does it mean that ArrayList is a generic class?
It can hold objects of any type specified between angle brackets, but only one type per list.
What is the default size of a new ArrayList?
It starts empty and automatically grows as elements are added.
How do you add an element to an ArrayList?
list.add(element);
How do you insert an element at a specific index?
list.add(index, element);
How do you remove an element from an ArrayList?
list.remove(index);
How do you access an element from an ArrayList?
list.get(index);
What method returns the number of elements in an ArrayList?
list.size();
How do you replace an element at a specific index?
list.set(index, newValue);
How do you clear all elements from a list?
list.clear();
What is the purpose of toString() in ArrayList?
It returns a readable string representation of the list’s contents.
What happens if you try to access an invalid index?
Java throws an IndexOutOfBoundsException.
How are ArrayLists different from arrays?
Arrays have fixed length; ArrayLists can resize dynamically.
What type of data can an ArrayList store?
Only objects, not primitive types (e.g., use Integer instead of int).
What are wrapper classes in Java?
Classes like Integer, Double, and Boolean that wrap primitive types into objects.
What are the time complexities of key ArrayList operations?
Access: O(1), Insertion/Removal (end): O(1), Insertion/Removal (middle): O(n).
What interface does ArrayList implement?
java.util.List
What is the benefit of programming to the List interface?
It allows flexible switching between different list implementations like ArrayList and LinkedList.
How does ArrayList handle resizing internally?
It doubles its capacity when the current array becomes full, copying elements into a larger array.
What are some common use cases for lists?
Storing game objects, managing GUI elements, or maintaining ordered sequences of data.
How can you iterate through an ArrayList?
Using a standard for loop, an enhanced for-each loop, or an Iterator.
What is an Iterator?
An object that provides sequential access to elements of a collection.
What method checks if an ArrayList contains a specific value?
list.contains(value);
How do you find the index of an element?
list.indexOf(value);
What does the equals() method do for lists?
Compares two lists for element-by-element equality.
What is the relationship between lists and arrays?
Lists provide higher-level, flexible abstraction over low-level arrays.
What happens when elements are removed from an ArrayList?
Remaining elements are shifted left to fill the gap.
Why might ArrayList be inefficient for frequent insertions?
Because elements must be shifted when inserting or deleting from the middle.
What are the benefits of ArrayList?
Fast random access, easy resizing, and built-in methods for manipulation.
What are the drawbacks of ArrayList?
Slower insertions and deletions in the middle compared to linked structures.
What concept does Chapter 6 introduce alongside lists?
Interfaces and polymorphism — allowing flexible data structures.
What project accompanies Chapter 6?
A dynamic graphical project like Snake or particle animation using lists to track moving objects.
What is the key learning objective of Chapter 6?
To understand dynamic storage, interfaces, and how collections enable flexible data-driven programming.