Arrays in Java
Arrays in Java
Introduction to Arrays
• An array is a collection of similar types of data having contiguous memory allocation.
• The indexing of the array starts from 0., i.e 1st element will be stored at the 0th index, 2nd element
at 1st index, 3rd at 2nd index, and so on.
• The size of the array can not be increased at run time therefore we can store only a fixed size of
elements in array.
Note : Array index start from 0 and go till (n-1) where n is the size of the array.
Looping Through Array output
Elements
class Main { Using for Loop:
public static void main(String[] args) { 12
4
// create an array 5
int[] age = {12, 4, 5};