How to find Length of Array
public class Main { public static void main(String args[]) { int[] a = {1,2,3,4,5}; System.out.println("Length of array " + a.length); } }
Two Dimensional Array – Java
class Main { public static void main(String args[]) { int[][] a = {{1,2}, {3,4}}; System.out.println("Content of array " + a[0][1]); System.out.println("Length of array " + a[0].length); } }
OP: Content of array 2
Length of array 2
public class Main11 { public static void main(String args[]) { String[] arrName = new String[5]; int[] arrAge = {21, 25, 24, 26, 27}; char[] arrSection = {'A', 'B', 'C', 'D', 'E'}; arrName[0] = "Mugil"; arrName[1] = "Vinu"; arrName[2] = "Madhavan"; arrName[3] = "Adhavan"; arrName[4] = "Suryan"; //Method 1 for(int i=0;i<arrName.length;i++) { if(arrName[i] != null) System.out.println(arrName[i]); } //Method 2 //For - Each Method for(String item : arrName) { System.out.println(item); } //Method 3 int j =0; while(j<arrAge.length) { System.out.println(arrAge[j]); j++; } //Method 4 int k=0; do { System.out.println(arrSection[k]); k++; }while(k<arrSection.length); } }