Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions 2DjaggedArray
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Program {
public static void main(String[] args) {

// Create an array of String arrays: a jagged array.
String[][] values = new String[2][];

// Fill first row with 2-element array.
values[0] = new String[2];
values[0][0] = "cat";
values[0][1] = "dog";

// Use 3-element array for second row.
values[1] = new String[3];
values[1][0] = "fish";
values[1][1] = "bird";
values[1][2] = "lizard";

// Display rows and elements.
for (String[] array : values) {
for (String element : array) {
System.out.print(element);
System.out.print(" ");
}
System.out.println();
}
}
}