Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Beginners Arrayexamples Java Array Declaration

Related Tutorials


 
 

Share on Google+Share on Google+

Java Array Declaration

Advertisement
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];
 }
}
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 28, 2007

Related Tutorials

Discuss: Java Array Declaration   View All Comments

Post your Comment


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

is very nice easily understanding
dudhrejiya vipul
February 7, 2013
java

java program is good programing lanluage
anil
June 19, 2012
array

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]); } }
jason
September 3, 2012
COMPUTER

NICE !!!
danishakhtar18@gmail.com
December 7, 2012
java

job
MAPULANGA CHRISTOPHER MWELWA
October 23, 2012
ARRAYS - JAVA

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.
theena
July 2, 2013
java array

it is use full to me
DMCA.com