You are on page 1of 2

========================================

Array in Java:
An array is a container object that holds a fixed number of values of a single type

=========================================
3 basic information is needed to start with array
 Datatype
 Size of array
 Data in array

=========================================
Things to do with array:
 creation (datatype and size is required)
 initialization (datatype, size and values is required)
 manipulations

General process of array creation till initialization:


1. declaration of array (array reference creation) :
 dataType [ ] nameOfArray;
 dataType nameOfArray[ ];

2. instantiation of array(array object creation ) :


using new keyword
dataType [] nameOfArray = new dataType [size]

3.initialization of array(object initialization using constructor calling i.e putting values inside an array)
using new keyword
nameOfArray[index]=val1, nameOfArray[index]=val2,

Direct method to create an Array(Declaring ,Instantiation and Initialization of array)


using new keyword
dataType [] nameOfArray = new dataType [size]{val1,val2,val3};

using array literal


dataType[] nameOfArray= {val1,val2,val3};

Note :
 Array are created using two ways new keyword and using literal
 if we have size and elements are defined then literal is used
 when only datatype and size is known then new keyword is used

--------------------------------------------------------------------------
Manipulation of array :
 Arrays are manipulated using their index values
 Array index value start from the 0

Accessing single value of array :


nameOfArray[index]
Accessing multiple value of array using loops:
for(int index = 0; index < age.length; index++) {
System.out.println(age[index]);
}

Some methods for array:


.clone() : for deep copying the array
.length() : for finding length of array
java.utils.arrays provide methods for handling stuffs in array

study yourself the multiplication, addition of elements in array and between to array

=========================================
Array can be classified using Dimension
--------single dimension --------------
1Dimension: dataType nameOfArray[ ];

--------multidimensional Array---------
2Dimension: dataType nameOfArray[ ][ ];

multi Dimension: dataType nameOfArray[ ][ ][ ]...;

Note: all these arrays are created using same process as mentioned above

Special types of arrays


 anonymous array (array without and reference) these are passed are an argument or returned from the
methods

 jaggerd array:

 Final array:
=======================================
Final Note : arrays created using this method are static in nature as size of an array is immutable can’t be changed
dynamic arrays are created using Arraylist class

---------------------------------------------------------------------------the End---------------------------------------------------------------

You might also like