Array is the collection of similar elements which can be values or variables.
Initialising Arrays in Java
There are several ways to initialize arrays in Java
Define and Initialize at same time:
int myArray[] = new int[] {10,21,330,5,32,50,61,83,60,23 };
Define and then initialize later:
int data[]; data=new int[] {10,20,30,40,50,60,71,80,90,91 };
Method 3 :
int[] data = {10,20,30,40,50,60,71,80,90,91};
One more method to initialize array in Java:
public class MyArray { int num[] = new int[10];
/** New instance of Array */
public MyArray() { for(int i = 0; i < num.length; i++) { data[i] = i*10; // Any value } } }
0 comments:
Post a Comment