1/43
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Data Collections
Allow us to store and manipulate groups of related data under a single variable name.
1D Arrays
A fixed-size data structure that holds multiple values of the same type.
Declaration and Initialization
The process of setting up an array using either 'new' or an initializer list.
Default Values
Values automatically assigned by Java when an array is initialized with 'new'.
Zero-based indexing
The practice of starting array indices at 0 instead of 1.
Length of an array
The number of elements in the array, accessed using 'array.length'.
Standard for loop
A loop structure allowing index access to array elements.
Enhanced for-each loop
A loop used for simple traversals of arrays, does not allow modification of elements.
Accumulator
A variable used to maintain a running total during iteration.
Finding Minimum/Maximum
Technique that initializes min/max variables to the first element and compares subsequent elements.
ArrayList
A dynamic data structure that can resize itself and manages memory automatically.
Wrapper Classes
Classes that allow primitive types to be stored in collections, such as Integer and Double.
Autoboxing
The automatic conversion of a primitive type to its corresponding wrapper class.
Essential ArrayList methods
Includes methods like size(), add(), get(), set(), and remove() for manipulation of list elements.
Visualizing Insertion and Deletion
Understanding how the indices change when using add or remove methods on ArrayLists.
Concurrent Modification Error
An error that occurs when a collection is modified during iteration using an enhanced for loop.
ArrayIndexOutOfBoundsException
An error that occurs when accessing an invalid index in an array.
set vs add
'set' replaces an element without changing size, 'add' inserts an element and increases size.
Comparing Objects
Use .equals() instead of == to compare contents of objects.
Accessing Elements in 1D Array
Example: 'int x = scores[2];' retrieves the value at index 2.
Modifying Elements in 1D Array
Example: 'scores[2] = 95;' changes the element at index 2.
Traversing Arrays
Using loops to process data in an array efficiently.
Warning regarding removal in loops
Using a standard increasing for loop while removing elements may skip elements.
Safer method for removal in ArrayLists
Traverse an ArrayList backwards when removing elements.
System.out.println(myArray)
Prints a memory hash code, not the values of the array.
Arrays.toString(myArray)
Method used to print the values of an array correctly.
Java's default array values for int
Int arrays default to 0 when initialized with 'new'.
Heap memory management
ArrayLists handle their own memory allocation and resizing.
Memory reference
Objects in ArrayLists are stored as references rather than primitive values.
Primitive types
Basic data types like int and double that cannot be stored directly in ArrayLists.
Algorithm for Sum/Average
A technique that iterates through the elements to calculate the total and average.
IndexOutOfBoundsException
Occurs when an index accessed is greater than or equal to the length of the array.
ArrayList size method
'size()' returns the number of elements in the ArrayList.
add(int index, E obj)
Inserts an element at a specified index, shifting subsequent elements.
get(int index) in ArrayList
Returns the element at the specified index of the ArrayList.
set(int index, E obj)
Replaces the current element at the given index with a new element.
remove(int index)
Removes the element at the specified index in an ArrayList.
String length() method
Called to get the number of characters in a String, differs from array length.
Avoid using == for Strings
Use .equals() to compare the contents of Strings instead of the reference.
Memory efficiency of ArrayLists
ArrayLists are more memory efficient due to dynamic resizing compared to fixed arrays.
Initializing an array using initial values
Example: String[] fruits = {'Apple', 'Banana', 'Cherry'}; uses an initializer list.
The enhanced for loop syntax
The syntax is 'for (DataType tempVar : arrayName)'.
Accessing array length
Remember to use arrayName.length without parentheses to view length.
Output of System.out.println() on ArrayList
Automatically prints elements in a user-friendly format like [A, B, C].