Here's just some of what you'll learn?
An array is a collection of similar data types. Array is a container object that hold values of homogeneous type. It is also known as static data structure because size of an array must be specified at the time of its declaration.
Array starts from zero index and goes to n-1 where n is length of the array.
In Java, array is treated as an object and stores into heap memory. It allows to store primitive values or reference values.
Array can be single dimensional or multidimensional in Java.
Features of Array
- It is always indexed. Index begins from 0.
- It is a collection of similar data types.
- It occupies a contiguous memory location.
- It allows to access elements randomly.
Single Dimensional Array
Single dimensional array use single index to store elements. You can get all the elements of array by just increment its index by one.
Java allows to declare array by using both declaration syntax, both are valid.
The arrayName can be any valid array name and datatype can be any like: int, float, byte etc.
int[ ] arr;
char[ ] arr;
short[ ] arr;
long[ ] arr;
int[ ][ ] arr;
Initialization of Array
Initialization is a process of allocating memory to an array. At the time of initialization, we specify the size of array to reserve memory area.
arrayName = new datatype[size]
Powered by Froala Editor