Last Updated: 06 October, 2024 5 Mins
An array is an object that stores collections of elements with the same data type. The length of an array is fixed at the time of creation, and it cannot be modified after that.
An array allocates contiguous memory locations for each element. An array is an index-based data structure; each element is accessed by its unique numerical index value, which starts at 0, which means the first element of the array will be stored at the 0th index position, the second element will be stored at the 1st index position, and so on. Using the index number, we can directly access any random value from the array.
Here, 10 characters size of Array is created which means Array length is 10 and storing values like A, B, C, D, E, F, G, H, I, J. Since at the time of array declaration, the character 'A' is declared first and then 'B' character and so on, therefore 'A' will be store at the 0 index position and 'B' will be store at index 1 and so on.
Let's understand this with a simple example. Supposing we have to store multiple records of the same date type, such as the name of each student in a class, instead of creating multiple variables for each student name, we will create an array and store all the names of students in a single object.
Moreover, an array provides some other benefits, such as random access to elements. Arrays store elements in contiguous memory locations.
Java supports mainly two types of Array:
An array with one dimension is called a one-dimensional array or single-dimensional array in Java. A Single Dimensional Array stores the same data-types values in a sequential fashion. Its length is fixed once created and cannot be changed.
A single-dimensional Array allocates contiguous memory locations for each element in Java.
A multidimensional array is an array of arrays. It has more than one row and it represents the data in a tabular form (Rows and columns).
To access data or elements in the two-dimensional array we use row index and column index.
That's all, guys. I hope this article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com