Java Array
Java Array
Java Array
Java Arrays
Arrays are used to store multiple values in a single variable,
instead of declaring separate variables for each value.
To declare an array, define the variable type with square
brackets:
String[] cars;
Java Arrays
We have now declared a variable that holds an array of
strings. To insert values to it, we can use an array literal -
place the values in a comma-separated list, inside curly
braces:
Note: Array indexes start with 0: [0] is the first element. [1]
is the second element, etc.
Change an Array Element
To change the value of a specific element, refer to the index
number:
Change an Array Element
To change the value of a specific element, refer to the index
number:
Array Length
To find out how many elements an array has, use the length
property: