Thursday 19 January 2017

Arrays in Java


                                                
arrays in java


 An Array is a group of Homogeneous Data Elements stored in contiguous memory location. By the term " Homogeneous " , we means elements with same data type. A specific element in array is accessed by its index.

There are 2 types of Array :

- One Dimensional Array : A one dimensional array is a list of liked type elements.

The syntax for the same is :  type   Array_name [Size_of_array];

The array can be initialized when they are declared. An array initializer is a list of comma seperated expressions surrounded by curly braces.

The array will automatically created large enough to hold the number of elements you specify in the array initializer. There is no need to use new operator.

Java strictly checks to make sure you do not accidentally try to store or reference value outside of the range of the array. The java run-time system will check to be sure that all array indexes are in the correct range.

-Multi Dimensional Array : The multi dimensional arrays are actually arrays of arrays. To declare a multi dimensional array variable, specify each additional index using another set of square brackets.

The syntax for the same is : type array_name [][];

When you allocate memory for a multidimensional array , you need only specify the memory for the first dimension . You can allocate the remaining dimension separately.

If we allocate dimensions manually , we do not need to allocate the same number of elements for each dimension. As it is arrays of arrays , the length of each array is under control.

It is possible to initialize multidimensional arrays. To do so , we simply enclose each dimension's initializer within its own set of curly braces. 

No comments:

Post a Comment

Video of the Day

Contact us

Name

Email *

Message *