Array Initialization
From Java Example Source Code
Contents |
[edit] Overview - Array Initialization
This Java example program shows how to initialize an array.
[edit] Java Source Code
- Package: example.array
- File: TestArray.java
package example.array;
/** 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]);
}}
[edit] What Result You Can Get
Run the program, you will get:
The length of the array is 4 The element at index 2 is 3
[edit] Required External Libraries and/or Files for this Java Example
Need nothing.
[edit] How to Run this Java Example Program
We recommend running this Java example program with Eclipse.
For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.
It's fairly easy.
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.
