My 2ND DSA LAB
As a week after my first Blog I have attended my 2nd LAB. Which is on the topic on Arrays and it’s properties,uses,methods,Algorithms.
What is an Array?
We can say it is a collection of similar data types. It stores the Fixed-sized sequential collection of Elements of Same data type.It starts Indexing from zero.Means our first Inserted Element will be stored on index 0.
Syntax’s:-
Arrays can be Defined or Created by 3 methods in Java:-
1-array_reference_variable=new data_type[length of array];
2-data_type array_reference_variable=new data_type[ length of array];
3-data_type array_reference_variable={element_0,element_1,element_2,…..,element_n};
data_types={int,String,char etc}
array_reference_variable={Any reference variable we want to create}
n={last element of array}
Use:-
Arrays are fast because they let you directly access a single element’s data in one computer cycle regardless of the size of the array.
Multi-Dimensional Arrays:-
It is an Array of 2 or more than 2 dimensions in Array.Matrices are the Basic main example of Multi-Dimensional Arrays.There are the Extension of 2-D matrices and use additional sub-scripts for indexing.They are very Helpful in Programming.
Syntax:-
It can be Declared by 2 methods in Java.
(i)Indirect Method:-
Declaration:-
data_type[][] Array_name = new data_type[x][y];
For Example:- Int[][] array1=new Int[5][10];
Intialization:-
Array_name[row_index][column_index] = value;
For Example:- array1[0][0]=1;
(ii)Direct Method:-
In this method Declaration and Intialization is done in the same line.
Declaration & Intialization:-
data_type[][] Array_name = { {valueR1C1, valueR1C2, ....}, {valueR2C1, valueR2C2, ....} };
Use:-
Basically we use it for declaring Arrays of Array.
This will be Continued in my 3RD Blog so keep Connected.