---
title: "Array in Java"  
description: "Array in Java"  
author: "Nitin Kushwaha"  
published: 2019-07-10  
updated: 2019-07-10  
canonical: https://www.mindstick.com/forum/55158/array-in-java  
category: "java"  
tags: ["array"]  
reading_time: 2 minutes  

---

# Array in Java

## Java [Arrays](https://www.mindstick.com/articles/11955/arrays-and-its-limitations):-

- Arrays mean that to store the homogenous (similar data type) data value.
- Arrays stored the element in a contiguous [memory](https://www.mindstick.com/blog/300050/what-causes-sudden-memory-loss) location.
- Array in Java is index-based, the first [element of the array](https://www.mindstick.com/forum/158053/how-to-remove-the-matching-element-of-the-array-in-javascript) is stored at the 0th index, and the second element is stored on the first index and so on.
- In Java, we can also generate single dimensional or [multidimensional array](https://www.mindstick.com/forum/23344/multidimensional-array-of-nsinteger-as-instance-variable) in java.
- The main [disadvantages](https://www.mindstick.com/blog/300577/advantages-and-disadvantages-of-web-3-0) of arrays are, we can store the only fixed size of data.

**Types of Array in java:**-

There are two types of array:-

- Single Dimensional Array.
- Multidimensional Array.

## Declaration of arrays:-

```
data_type array_name[array_size];
```

## Example:-

float mark [5];

**[Access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) the [Elements of an Array](https://www.mindstick.com/forum/157607/how-to-use-reduce-to-double-the-elements-of-an-array-in-javascript)**

We can access an array element by referring to the index number. This statement accesses the value of the first element in cars:

## Example

```
String [] cars = {"Volvo", "BMW", "Ford", "Mazda"};
System.out.println(cars[0]);
// Outputs Volvo.
```

**Array Length:-**

To find out how many elements an array by using the length [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp):

## Example

```
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
System.out.println(cars.length);
// Outputs 4.
```

**Example of Java Array**

**Single [Dimension](https://www.mindstick.com/articles/1508/dimension-and-metrics-in-google-analytics-api-using-asp-dot-net-mvc)**

```
class Studentarray
{
public static void main(String args[])
{
int a[]=new int[5]
a[0]=450;
a[1]=320;
a[2]=75;
a[3]=43;
a[4]=502;
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
}
}
Output:-
450
320
75
43
502
```

## Multidimensional Array

```
class Studentarray
{
public static void main(String args [])
{
int a[][]={{1,2,3},{4,5,6},{7,8,9}};
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
System.out.println(arr[i][j]+" ");
 }
 System.out.println();
}
}
}
Output:-
1 2 3
4 5 6
7 8 9
```

\


---

Original Source: https://www.mindstick.com/forum/55158/array-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
