Array adalah suatu kumpulan data pada suatu variabel. Cara mendeklarasikan array adalah sebagai berikut:
type_array nama_array[];
example :
- int []ages;
- int ages[];
After declaring, we must create the array and specify its length with a constructor statement.
Definitions:
– Instantiation
– Instantiation
- In Java, this means creation
– Constructor
- In order to instantiate an object, we need to use a constructor for this. A
constructor is a method that is called to create a certain object.
- We will cover more about instantiating objects and constructors later.
Array Instantiation
- To instantiate (or create) an array, write the new keyword,
followed by the square brackets containing the number of
elements you want the array to have.
elements you want the array to have.
- For example,
//declaration
int ages[];
//instantiate object
ages = new int[100];
or, can also be written as,
//declare and instantiate object
int ages[] = new int[100];
int ages[];
//instantiate object
ages = new int[100];
or, can also be written as,
//declare and instantiate object
int ages[] = new int[100];
Download full article in here