Java examples for Language Basics:Array
Default Initialization of Array Elements
public class Main { private boolean[] myArray = new boolean[3]; // An instance variable public Main() { for (int i = 0; i < myArray.length; i++) { System.out.println("bArray[" + i + "]:" + myArray[i]); }//from w ww.j a v a 2 s . c om } public static void main(String[] args) { System.out.println("int array initialization:"); int[] empId = new int[3]; // A local array variable for (int i = 0; i < empId.length; i++) { System.out.println("empId[" + i + "]:" + empId[i]); } System.out.println("boolean array initialization:"); new Main(); System.out.println("Reference type array initialization:"); String[] name = new String[3]; for (int i = 0; i < name.length; i++) { System.out.println("name[" + i + "]:" + name[i]); } } }