1/23
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Enhanced For / For Each Loop
A special for loop for going through all the items in a data set.
Index
A location in an array, where a value is stored.
1D Array Creation (Size Known)
type[] name = new type[size];
1D Array Creation (Size and Values Known)
type[] name = {value,value,value,value,..., value};
Replacing a 1D Array
name = new type[]{value,value,value,value,..., value};
Getting the Size of a 1D Array
name.length
Accessing Value at an Index
name[index]
Changing Values in an Array
name[index] = value;
Array
A structure for storing multiple values in a single variable.
Element
A single value stored by an array.
Printing All Values in an Array
for(int x = 0; x < name.length; x++) System.out.println(name[x]);
For Each Loop Format
for(typeOfDataInArray variableName: arrayName) // code using the variableName
Turning a String into a char Array
char[] arrayName = StringName.toCharArray();
Null Pointer Exception
Occurs if an array variable stores null and you try to access or change an element.
Arrays Class
The Arrays class has methods to perform operations on arrays.
Arrays Class Import Statement
import java.util.Arrays;
Arrays Class Method: sort
sort(arrayName) - Sorts the given array.
Arrays Class Method: toString
toString(arrayName) - Prints the given 1D array.
Arrays Class Method: deepToString
deepToString(arrayName) - Prints the given 2D array.
First Index of an Array
The first index in an array is at index 0.
Last Index of an Array
The last index is (number of elements stored) - 1.
Automatic Initialization of int and double Arrays
Values will be initialized to 0 automatically.
Automatic Initialization of boolean Arrays
Values will be initialized to false automatically.
Automatic Initialization of Object Arrays
Values will be initialized to null automatically.