zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcard
Study GuideStudy GuideQuestion BankQuestion BankGlossaryGlossary

What is an ArrayList?

A resizable array that can grow or shrink as needed.

Flip to see [answer/question]
Flip to see [answer/question]
Revise later
SpaceTo flip
If confident

All Flashcards

What is an ArrayList?

A resizable array that can grow or shrink as needed.

What is the .size() method in ArrayLists?

Returns the number of elements currently in the ArrayList.

What is the .set() method in ArrayLists?

Replaces the element at the specified position in the ArrayList with the specified element.

What is the .get() method in ArrayLists?

Returns the element at the specified position in the ArrayList.

Define 'mode' in the context of an ArrayList.

The element that appears most frequently in the ArrayList.

Define 'mean' in the context of an ArrayList.

The average value of the elements in the ArrayList.

What does 'traverse' mean in the context of ArrayLists?

To iterate through each element of the ArrayList.

What is the purpose of a 'defaultName' parameter in the context of the provided code?

A string used to reset all student names in an ArrayList of Student objects.

What is the purpose of the 'add' method in ArrayLists?

Appends the specified element to the end of the ArrayList.

What is the difference between an Array and an ArrayList?

Arrays have a fixed size, while ArrayLists are resizable.

What does the following code output?

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(1, 2, 3));
doubleArray(arr);
System.out.println(arr);

assuming doubleArray is the method provided in the notes.

[2, 4, 6]

Identify the error in the following code:

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(1, 2, 3));
int sum = sum(arr);
System.out.println(sum / (arr.size()));

Integer division will truncate the decimal part of the mean. Should cast to double either sum or arr.size().

What does the following code output?

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(1, 2, 2, 3, 3, 3));
System.out.println(mode(arr));

assuming mode is the method provided in the notes.

3

What does the following code output?

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(2, 4, 6, 8));
System.out.println(isEven(arr));

assuming isEven is the method provided in the notes.

true

What does the following code output?

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
returnAllConsecutiveSequences(arr, 3);

assuming returnAllConsecutiveSequences is the method provided in the notes.

1 2 3 2 3 4 3 4 5

What does the following code output?

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(1, 2, 3, 2, 1));
System.out.println(duplicates(arr));

assuming duplicates is the method provided in the notes.

true

What does the following code output?

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6));
System.out.println(evenFrequency(arr));

assuming evenFrequency is the method provided in the notes.

3

What does the following code output?

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
System.out.println(shiftLeft(arr));

assuming shiftLeft is the method provided in the notes.

[2, 3, 4, 5, 1]

What does the following code output?

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
System.out.println(shiftRight(arr));

assuming shiftRight is the method provided in the notes.

[5, 1, 2, 3, 4]

What does the following code output?

java
ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5));
System.out.println(reverse(arr));

assuming reverse is the method provided in the notes.

[5, 4, 3, 2, 1]

What are the general steps to find the maximum value in an ArrayList?

Initialize maxValue to the first element, iterate through the ArrayList, compare each element with maxValue, and update maxValue if a larger element is found.

What are the general steps to find the minimum value in an ArrayList?

Initialize minValue to the first element, iterate through the ArrayList, compare each element with minValue, and update minValue if a smaller element is found.

What are the general steps to calculate the sum of elements in an ArrayList?

Initialize sum to 0, iterate through the ArrayList, and add each element to the sum.

What are the steps to calculate the mean of an ArrayList?

Calculate the sum of the elements, divide the sum by the number of elements, and cast to a double to preserve fractional parts.

What are the steps to determine if all values in an ArrayList have a certain property?

Iterate through the ArrayList, check if each element satisfies the property, and return false if any element does not satisfy the property. Return true if all elements satisfy the property.

What are the steps to check for duplicate elements in an ArrayList?

Use nested loops to compare each element with every other element. If any two elements are equal, return true. If the loops complete without finding any duplicates, return false.

What are the steps to shift elements one index to the left in an ArrayList?

Store the first element, iterate through the ArrayList, set each element to the value of the next element, and set the last element to the stored first element.

What are the steps to shift elements one index to the right in an ArrayList?

Store the last element, iterate through the ArrayList in reverse order, set each element to the value of the previous element, and set the first element to the stored last element.

What are the steps to reverse an ArrayList?

Create a new ArrayList, iterate through the original ArrayList in reverse order, and add each element to the new ArrayList.

What are the steps to transfer items from an ArrayList into an Array?

Create a new Array of the same size as the ArrayList, iterate through the ArrayList, and copy each element to the corresponding index in the Array.