What is an Array in data structure?
An array is a fixed-size container that holds a sequence of values of the same type. In Java an array is an object: you choose its length when you create it (for example new int[10]), and that length, available through the length field, never changes afterwards.
Every slot in an array has a numbered position called an index. Java indexes start at 0, so an array of length n has the indexes 0 to n − 1. Because the slots sit next to each other and all have the same size, the program can jump straight to any index without looking at the others. This is called random access, and it takes O(1) time.

The figure shows a char array of length 10. The letters A to J are stored in the order they were written in the initializer, so 'A' is at index 0, 'B' is at index 1, and 'J' is at the last index, 9.
Why do we need an array data structure?
Imagine storing the names of 60 students. Declaring 60 separate variables (name1, name2, …) would be impossible to loop over or pass to a method. A single String[] names = new String[60]; keeps all of them under one name, and a for loop can process every entry.
Arrays are also the building block for many other structures. ArrayList, ArrayDeque, HashMap and binary heaps all keep their data in arrays internally.
Advantages of Java Arrays
- Fast access by index: reading or writing
arr[i]takes O(1) time. - Low memory overhead: an array stores only its elements plus a small header; there are no per-element links as in a linked list.
- Can hold primitives: an
int[]stores plainintvalues, with no boxing intoIntegerobjects. - Cache friendly: elements that are next to each other in the array are usually next to each other in memory, so looping through an array is fast in practice.
Disadvantages of Java Arrays
- Fixed size: an array cannot grow or shrink. To store more elements you must create a larger array and copy the old values into it.
- Slow insertion and deletion in the middle: adding or removing an element at index i means shifting the elements after it, which is O(n) in the worst case.
- Unused space: if you allocate more slots than you need, the extra slots still take memory.
Types of Array in Java
By the number of indexes needed to reach an element, Java arrays come in two forms:
- Single Dimensional Array
- Multi Dimensional Array
Single Dimensional Array
A one-dimensional array is a simple list of values reached with one index, such as int[] marks = {72, 85, 90}; where marks[1] is 85.
Multi Dimensional Array
A multi-dimensional array is an array whose elements are themselves arrays. The most common case is the two-dimensional array, which is used like a table: the first index selects the row and the second selects the column, as in matrix[row][col].
Since each row is a separate array object, the rows of a Java 2D array do not have to be the same length. Arrays with rows of different lengths are called jagged arrays.