Normally, an array is a collection of similar type of elements which has contiguous memory location.
Java array is an object which contains elements of a similar data type. Additionally, The elements of an array are stored in a contiguous memory location. It is a data structure where we store similar elements. We can store only a fixed set of elements in a Java array.

Advantages:
- Code Optimization: It makes the code optimized, we can retrieve or sort the data efficiently.
- Random access: We can get any data located at an index position.
Disadvantages:
- Size Limit: We can store only the fixed size of elements in the array. It doesn’t grow its size at runtime. To solve this problem, collection framework is used in Java which grows automatically.
Example:
public class Array {
public static void main(String[] args)
{
int[] array= {10,20,30,40,50};
System.out.println(array[4]);
}
}

Array in loop:
public class Array
{
public static void main(String[] args)
{
int[] a= {90,78,56,79,92};
int total=0;
for(int i=0; i<a.length;i++)
{
total=total+a[i];
}
System.out.println(total);
}
}
output:

Why do we use length in array:
Note that length determines the maximum number of elements that the array can contain or the capacity of the array. It does not count the elements that are inserted into the array. That is, length returns the total size of the array.

public class
{
public static void main(String[] args)
{
int[] a={90,78,56,79,92};
System.out.println(a.length);
}
}
