Java Arrays in Hindi- 2D,3D Arrays

2
609
views
Java Array in Hindi -Core Java Hindi, Core Java Tutorials, Programming Language
Java Array in Hindi -Core Java Hindi, Core Java Tutorials, Programming Language

Java Arrays in Hindi

Definition of Java Arrays:-

An array is an Indexed collection of fixed no of homogeneous data elements.

Advantage:- We can represent multiple data element or value with the same name. so, it is best for readability purpose.

Disadvantages:-  We can’t increase /decrease it’s  size based on our requirement.

Hence memory point of view arrays is not recommended to use it.

But we can resolve this problem by using collections.

Java Arrays Declaration, Construction and Initialization into Single Line.

Java Arrays in Hindi -Core Java Hindi, Core Java Tutorials, Programming Language
Java Arrays in Hindi -Core Java Hindi, Core Java Tutorials, Programming Language

Syntax  Array:-

                Int[]  a;

                a= new int[3];

                a[0]= 1;  or   int[]  a= {1,2,3,4};

                a[1]= 2;

a[2]= 3;

a[3]= 4;

Syntax  Char:-

                char[]  ch = {‘g’ , ’u’ , ’i’ , ’d’ ,’e’};

                String[]  s= {“sunil”,”manohar”,”shailendra”};

2D Array Syntax:-

we can also use this syntax for 2D array.

Int [][]  g=  {{0,1,2},{3,4}};

3D Array Syntax:-

we can also use this syntax for 3D array.

                Int [][][]  g= {{{1,2,3},{4,5,6},{6}},{{7,8},{9,10},{11,12,13}}};

Array Initialization:-

After creation of array every element  is initialized with default values.

Int[] a = new int[3];

System.out.println(a);

System.out.println(a[0]);

Whenever we are trying to print any object reference internally to String() will be call which is implemented as follows.

To Specify array size the allowed data types are byte, short, int, char.  If we uses Any other data type we will get compile time error.

Take a simple Syntax Example for clarity

int[] g = new int[‘j’];

byte g = 1;

int[]  g= new int[g];

short s=2;

int[]  g= new int[s];

int[]  g=new int[21l];

int[]  g= new int[10.5];

Array Some of Valid Declaration

1D Array                      2D Array                   3D Array

int[]  g;

int[]  []g;

int[]   [][]a;

int  g[];

int[]  g[];

int[]   []a[];

int  []g;

int   []g[];

int[]   a[][];

int[][]  g;

int[][]   []a;

int  [][]g;

int[][]   a[];

int  g[][];

int    [][]a[];

int    []a[][];

int[][][]    a;

int   [][][]a;

int  a[][][];

Note:-  we can’t specify size of array during declaration;

Int[5]  g;               //it is wrong

You may like to check – Introduction about java in Hindi

LEAVE A REPLY

Please enter your comment!
Please enter your name here