multidimentional array java code example
Example 1: Multidimensional array in java
public class TwoDimensionalStringArray
{
public static void main(String[] args)
{
String[][] animals = {
{ "Lion", "Tiger", "Cheetah" },
{ "Deer", "Jackal", "Bear" },
{ "Hyena", "Fox", "Elephant" } };
for(int a = 0; a < animals.length; a++)
{
System.out.print(animals[a][0] + " ");
for(int b = 1; b < animals[a].length; b++)
{
System.out.print(animals[a][b] + " ");
}
System.out.println();
}
}
}
Example 2: Multidimensional array in java
public class TwoDimensionalArrayLength
{
public static void main(String[] args)
{
int[][] arrNumber = {
{ 1, 3, 5 },
{ 7, 9, 2 },
{ 1, 2, 3, 4, 5 } };
System.out.println("Java two dimensional array length: " + arrNumber.length);
}
}