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.
• Here, the above array cannot store more than 100 names. The
number of values in a Java array is always fixed.
How to declare an array in Java?
• In Java, here is how we can declare an array.
NOTE:
• Array indices always start from 0. That is, the first element of
an array is at index 0.
• If the size of an array is n, then the last element of the array
will be at index n-1.
How to Access Elements of an Array in
Java?
We can access the element of an array using the
index number. Here is the syntax for accessing
elements of an array,
Example: Access Array Elements
• Here, we are using the length property of the array to get the size of
the array.