Java: Chapter 6 Lists

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/37

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

38 Terms

1
New cards

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.

2
New cards

What is a list in computer science?

An ordered collection of elements that can grow or shrink in size and allows duplicate items.

3
New cards

What is the ArrayList class in Java?

A resizable list implementation from java.util that stores objects in a dynamically sized array.

4
New cards

How do you import ArrayList in Java?

import java.util.ArrayList;

5
New cards

How do you declare an ArrayList of strings?

ArrayList names = new ArrayList();

6
New cards

What does the part in ArrayList mean?

It specifies the element type using Java generics, ensuring type safety.

7
New cards

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.

8
New cards

What is the default size of a new ArrayList?

It starts empty and automatically grows as elements are added.

9
New cards

How do you add an element to an ArrayList?

list.add(element);

10
New cards

How do you insert an element at a specific index?

list.add(index, element);

11
New cards

How do you remove an element from an ArrayList?

list.remove(index);

12
New cards

How do you access an element from an ArrayList?

list.get(index);

13
New cards

What method returns the number of elements in an ArrayList?

list.size();

14
New cards

How do you replace an element at a specific index?

list.set(index, newValue);

15
New cards

How do you clear all elements from a list?

list.clear();

16
New cards

What is the purpose of toString() in ArrayList?

It returns a readable string representation of the list’s contents.

17
New cards

What happens if you try to access an invalid index?

Java throws an IndexOutOfBoundsException.

18
New cards

How are ArrayLists different from arrays?

Arrays have fixed length; ArrayLists can resize dynamically.

19
New cards

What type of data can an ArrayList store?

Only objects, not primitive types (e.g., use Integer instead of int).

20
New cards

What are wrapper classes in Java?

Classes like Integer, Double, and Boolean that wrap primitive types into objects.

21
New cards

What are the time complexities of key ArrayList operations?

Access: O(1), Insertion/Removal (end): O(1), Insertion/Removal (middle): O(n).

22
New cards

What interface does ArrayList implement?

java.util.List

23
New cards

What is the benefit of programming to the List interface?

It allows flexible switching between different list implementations like ArrayList and LinkedList.

24
New cards

How does ArrayList handle resizing internally?

It doubles its capacity when the current array becomes full, copying elements into a larger array.

25
New cards

What are some common use cases for lists?

Storing game objects, managing GUI elements, or maintaining ordered sequences of data.

26
New cards

How can you iterate through an ArrayList?

Using a standard for loop, an enhanced for-each loop, or an Iterator.

27
New cards

What is an Iterator?

An object that provides sequential access to elements of a collection.

28
New cards

What method checks if an ArrayList contains a specific value?

list.contains(value);

29
New cards

How do you find the index of an element?

list.indexOf(value);

30
New cards

What does the equals() method do for lists?

Compares two lists for element-by-element equality.

31
New cards

What is the relationship between lists and arrays?

Lists provide higher-level, flexible abstraction over low-level arrays.

32
New cards

What happens when elements are removed from an ArrayList?

Remaining elements are shifted left to fill the gap.

33
New cards

Why might ArrayList be inefficient for frequent insertions?

Because elements must be shifted when inserting or deleting from the middle.

34
New cards

What are the benefits of ArrayList?

Fast random access, easy resizing, and built-in methods for manipulation.

35
New cards

What are the drawbacks of ArrayList?

Slower insertions and deletions in the middle compared to linked structures.

36
New cards

What concept does Chapter 6 introduce alongside lists?

Interfaces and polymorphism — allowing flexible data structures.

37
New cards

What project accompanies Chapter 6?

A dynamic graphical project like Snake or particle animation using lists to track moving objects.

38
New cards

What is the key learning objective of Chapter 6?

To understand dynamic storage, interfaces, and how collections enable flexible data-driven programming.