Java examples for Language Basics:Array
The following code creates a jagged array.
public class Main { public static void main(String[] args) { String[][] teams = { { "H", "J" }, { "B", "J", "J" }, { "M", "F" }, { "M", "R", "I" } }; } }
Enhanced for loop with jagged array
public class Main { public static void main(String[] args) { String[][] teams = { { "H", "J" }, { "B", "J", "J" }, { "M", "F" }, { "M", "R", "I" } }; for (String[] team : teams) { for (String player : team) System.out.println(player); System.out.println();//from w w w . j a va2 s .com } } }