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

Glossary

A

ArrayIndexOutOfBoundsException

Criticality: 2

A runtime exception thrown when an attempt is made to access an array or ArrayList with an index that is either negative or greater than or equal to the size of the array/list.

Example:

Trying to access myList.get(myList.size()) on an ArrayList will cause an ArrayIndexOutOfBoundsException because the last valid index is size() - 1.

ArrayList

Criticality: 3

A resizable array implementation of the List interface in Java, capable of storing objects. It dynamically adjusts its capacity as elements are added or removed.

Example:

To manage a collection of student scores, you might declare ArrayList<Integer> studentScores = new *ArrayList*<Integer>();.

I

IndexOutOfBoundsException

Criticality: 2

A runtime exception, a subclass of `ArrayIndexOutOfBoundsException`, specifically thrown by `ArrayList` methods like `add(index, obj)` or `set(index, obj)` when the provided index is out of the valid range.

Example:

Attempting myList.add(10, "New Item") on an ArrayList of size 3 would throw an IndexOutOfBoundsException because index 10 is too large for insertion.

a

add(E obj)

Criticality: 3

A method of the ArrayList class that appends the specified element to the end of this list. It returns `true` to indicate successful addition.

Example:

If myShoppingList is ["milk", "bread"], calling myShoppingList.*add*("eggs") would result in myShoppingList becoming ["milk", "bread", "eggs"].

add(int index, E obj)

Criticality: 3

A method of the ArrayList class that inserts the specified element at the specified position in this list. Elements at or after the specified index are shifted one position to the right.

Example:

If mySchedule is ["Math", "Science"], calling mySchedule.*add*(1, "English") would result in mySchedule becoming ["Math", "English", "Science"].

g

get(int index)

Criticality: 3

A method of the ArrayList class that returns the element at the specified position in this list. The index must be within the valid range [0, size() - 1].

Example:

If teamMembers is ["Alice", "Bob", "Charlie"], then teamMembers.*get*(1) would return "Bob".

r

remove(int index)

Criticality: 3

A method of the ArrayList class that removes the element at the specified position in this list. Subsequent elements are shifted to the left, and the removed element is returned.

Example:

If toDoList is ["Buy groceries", "Walk dog", "Study"], calling toDoList.*remove*(0) would remove "Buy groceries" and toDoList would become ["Walk dog", "Study"].

s

set(int index, E obj)

Criticality: 3

A method of the ArrayList class that replaces the element at the specified position in this list with the specified element. It returns the element that was previously at that position.

Example:

If grades is [85, 90, 78], calling grades.*set*(2, 88) would change grades to [85, 90, 88] and return 78.

size()

Criticality: 3

A method of the ArrayList class that returns the number of elements currently in the list. This is equivalent to the 'length' for arrays.

Example:

If myPlaylist contains ["Song A", "Song B", "Song C"], then myPlaylist.*size*() would return 3.

z

zero-indexed language

Criticality: 3

A programming language where the first element in a sequence (like an array or list) is accessed at index 0, the second at index 1, and so on. Java is a zero-indexed language.

Example:

In Java, if you have an array int[] scores = {90, 85, 92};, the score 90 is found at scores[0], illustrating its zero-indexed nature.