Chapter six Java
Array
Definition:
Array is known as a set of consecutive memory location which can store
same data type with a common name.
We have two types of array:
One dimensional array
Multi dimensional array
One dimensional array
An array which has one index is known as One dimensional array.
To use an array in a program, you must declare a variable to reference
the array, and you must specify the type of array the variable can
reference. Here is the syntax for declaring an array variable:
dataType[] ArrayName; // preferred way.
or
dataType arrayRefVar[]; // works but not preferred way
Continue..
You can create an array by using the new operator with the following
syntax:
ArrayName = new dataType[arraySize];
The above statement does two things:
It creates an array using new dataType[arraySize];
It assigns the reference of the newly created array to the variable
Two dimensional array
An array which has two indexes is known as two dimensional array, the
steps needed for declaration and creation of two dimensional array is
same like one dimensional array with little difference.
Here is the syntax for declaring array variable:
Data_type[][] array_name// mostly preferred
Or
Data_type array_name[][]// will work but not preferred
Continue..
After declaring an array name then one can create an array with
specific size:
Array_name = new data_type[index1][index2];
Thank You

Chapter 6 java

  • 1.
  • 2.
    Array Definition: Array is knownas a set of consecutive memory location which can store same data type with a common name. We have two types of array: One dimensional array Multi dimensional array
  • 3.
    One dimensional array Anarray which has one index is known as One dimensional array. To use an array in a program, you must declare a variable to reference the array, and you must specify the type of array the variable can reference. Here is the syntax for declaring an array variable: dataType[] ArrayName; // preferred way. or dataType arrayRefVar[]; // works but not preferred way
  • 4.
    Continue.. You can createan array by using the new operator with the following syntax: ArrayName = new dataType[arraySize]; The above statement does two things: It creates an array using new dataType[arraySize]; It assigns the reference of the newly created array to the variable
  • 5.
    Two dimensional array Anarray which has two indexes is known as two dimensional array, the steps needed for declaration and creation of two dimensional array is same like one dimensional array with little difference. Here is the syntax for declaring array variable: Data_type[][] array_name// mostly preferred Or Data_type array_name[][]// will work but not preferred
  • 6.
    Continue.. After declaring anarray name then one can create an array with specific size: Array_name = new data_type[index1][index2];
  • 7.