1// two dimensional string array in java example
2public class TwoDimensionalStringArray
3{
4 public static void main(String[] args)
5 {
6 String[][] animals = {
7 { "Lion", "Tiger", "Cheetah" },
8 { "Deer", "Jackal", "Bear" },
9 { "Hyena", "Fox", "Elephant" } };
10 for(int a = 0; a < animals.length; a++)
11 {
12 System.out.print(animals[a][0] + " ");
13 for(int b = 1; b < animals[a].length; b++)
14 {
15 System.out.print(animals[a][b] + " ");
16 }
17 System.out.println();
18 }
19 }
20}
1int[][] multiples = new int[4][2]; // 2D integer array with 4 rows
2 and 2 columns
3String[][] cities = new String[3][3]; // 2D String array with 3 rows
4 and 3 columns
1class MultidimensionalArray {
2 public static void main(String[] args) {
3
4 int[][] a = {
5 {1, -2, 3},
6 {-4, -5, 6, 9},
7 {7},
8 };
9
10 for (int i = 0; i < a.length; ++i) {
11 for(int j = 0; j < a[i].length; ++j) {
12 System.out.println(a[i][j]);
13 }
14 }
15 }
16}