In order to get the number of elements in an array, you can use the length field of an array. The length field of an array returns the size of the array.
Syntax:
arrayName.length
Example:
int[] num = new int [100];
for (int counter = 0; counter<num.length; counter++)
- The length of an arra is how many slots it has. An array of length Number for example has slots indexed 0- (Number -1).
-All indexes should be of Integer type.
-Every-time your compiler says the error. System Out of Bounds something like that. You should automatically know that the problem is with your array. don't waste your time by reading all-through-out your program.
Arrays must be declared like variables. When declaring an array, you list the data type, followed by a set of square brackets [], followed by the identifier name.
An Array stores multiple data items of the same datatype, in a contiguous block of memory, divided into a number of slots.
Array is an object that is used to store lists of values. It is made out of contiguous block of memory that is divided into a number of slots. Each slots holds a value and all slots has the same data type.
- Arrays have indexes
- Indexes are used to access any of the slots.