Java Array Declaration

In this section, you will learn how to declare array in Java.

Java Array Declaration


As we declare a variable in Java, An Array variable is declared the same way. Array variable has a type and a valid Java identifier i.e. the array's type and the array's name. By type we mean the type of elements contained in an  array. To represent the variable as an Array, we use [] notation. These two brackets are used to hold the array of a variable.

By array's name, we mean that we can give any name to the array, however it should follow the predefined conventions. Below are the examples which show how to declare an array :-

int[] array_name;   //declares an array of integers
String[] names;
int[][] matrix;  //this is an array of arrays

It is essential to assign memory to an array when we declare it. Memory is assigned to set the size of the declared array. for example:

int[] array_name = new int[5];

Here is an example that creates an array that has 5 elements.

public class Array
 public static void main(String[] args)
  int[] a = new int[5];
Share on Google+Share on Google+

Java Array Declaration

Posted on: May 28, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Java Array Declaration   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
July 6, 2011
thank u

is very nice easily understanding
dudhrejiya vipul
February 7, 2013

java program is good programing lanluage
June 19, 2012

why this program is not working. class ar { int[] a; a=new int[3]; a[0]=1; a[1]=2; a[2]=3; } class demo { public static void main(String[]arg) { ar b=new ar(); System.out.println(b.a[0]); } }
September 3, 2012

NICE !!!
[email protected]
December 7, 2012

October 23, 2012

Create an array of 10 values (2.3,3.44,1.22,7.99,8.33,6.72,4.67,5.33,3.78,7.77). Using for seperate methods, create a total of all the 10 values, secondly, search arrays and return values that are less than 5.2, thirdly find their average and lastly return values that are greater than the average.
July 2, 2013
java array

it is use full to me