- Array = a data structure used to implement a collection (list) of primitive or object reference data
- Element = a single value in the array
- Index = the position of the element in the array (starts from 0)
- Array Length = the number of elements in the array
- Array: a data structure used to implement a collection (list) of primitive or object reference data
- Element: a single value in the array
- Index: the position of the element in the array (starts from 0)
- Array Length: the number of elements in the array Is public, so can be accessed in any class Is also final, so can’t change it after array has been created
- Nested loops: Used to traverse 2D Arrays
public class Test {
public static void main(String[] args) {
int[][] arr = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
System.out.println("arr[0][0] = " + arr[0][0]);
System.out.println("arr[1][2] = " + arr[1][2]);
System.out.println("arr[2][1] = " + arr[2][1]);
}
}
Test.main(null);
public class Test {
public static void main(String[] args) {
String[][] arr = {
{ "a", "f", "g" },
{ "b", "e", "h" },
{ "c", "d", "i" }
};
// Print the last element in the array!
print()
}
}
Test.main(null);
public class Test {
public static void main(String[] args) {
String[][] arr = {
{ "Atlanta", "Baltimore", "Chicago" },
{ "Australia", "Boston", "Cincinnati" },
{ "Austin", "Beaumont", "Columbus" }
};
String longest = arr[0][0];
}
}
Test.main(null);