Advertisement
Google Ad Slot: content-top
Java Array
An array in Java is a container object that holds a fixed number of elements of the same type. It is a data structure used to store multiple values in a single variable, making it easier to manage collections of data.
Types of Arrays
- One-Dimensional Array: A list of elements in a single row.
- Multi-Dimensional Array: Arrays with multiple rows and columns (e.g., 2D arrays).
One-Dimensional Array:
Syntax:
dataType[] arrayName = newdataType[size];
Multi-Dimensional Array:
Syntax:
dataType[][] arrayName = new dataType[rows][columns];
Enhanced For Loop (For-Each Loop):
The for-each loop is used to iterate over arrays or collections without using an index. It's simpler and avoids potential errors with index handling.