Initializing Array Values

/*
This example creates a four element array with 1, 2, 3, 4 as the values.
The length of the array, and the element at index 2, are printed out.
*/
public class TestArray {
public static void main(String args[]) {
int[] data = {
1, 2, 3, 4
};
System.out.println("The length of the array is " + data.length);
System.out.println("The element at index 2 is " + data[2]);
}
}
Related examples in the same category