Get Adobe Flash player

Saturday, January 14, 2012

Arrays in Java

An array is a variable representing a collection of same-typed data. Arrays are usefull in representing vectors, matrix, string analysis, sorting a tables.

 

One-Dimensional Array:

In java, an array is created in two steps. First, an array variable is to be declared and the second is to create a array object using new operator by specifying the number of memory location required. These two operations are done using two different statements.

int arr[];
arr=new int[10];


The first statement int arr[]; declare a Integer type variable arr. The second statement allocates memory for 10 int type. Now arr can handle 10 int type values. Each value can be accessed by using index value 0 to 9. Supposing 10 elements are 12,32,43,13,25,34,76,45,23,34 then.



arr[0] ---> 12

arr[1] ---> 32


arr[6] ---> 76


and so on……

2 comments:

Rajasekar said...

Thanks for sharing this blog.. very informative..
MVC Training in Chennai
MVC Classes in Chennai

shreekavi said...

Wonderful post and more informative!keep sharing Like this!
DOT NET Training in Bangalore
Dot Net classes in Pune
.Net Training in Hyderabad
Dot Net Training Institute in Delhi
Dot Net Training in Gurgaon

Post a Comment