forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRaggedArray.java
More file actions
27 lines (26 loc) · 922 Bytes
/
RaggedArray.java
File metadata and controls
27 lines (26 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// arrays/RaggedArray.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
import java.util.*;
public class RaggedArray {
static int val = 1;
public static void main(String[] args) {
SplittableRandom rand = new SplittableRandom(47);
// 3-D array with varied-length vectors:
int[][][] a = new int[rand.nextInt(7)][][];
for(int i = 0; i < a.length; i++) {
a[i] = new int[rand.nextInt(5)][];
for(int j = 0; j < a[i].length; j++) {
a[i][j] = new int[rand.nextInt(5)];
Arrays.setAll(a[i][j], n -> val++); // (1)
}
}
System.out.println(Arrays.deepToString(a));
}
}
/* Output:
[[], [[1], [2], [3, 4, 5, 6]], [[], [7, 8], [9, 10]],
[[11, 12, 13], [14], [15, 16, 17, 18]], [[19, 20, 21],
[22, 23, 24], [25], []], [[26], [], [27]]]
*/