回答編集履歴
2
リンクの追加
test
CHANGED
@@ -95,3 +95,17 @@
|
|
95
95
|
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
96
96
|
|
97
97
|
```
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
参考
|
102
|
+
|
103
|
+
---
|
104
|
+
|
105
|
+
安定の公式リファレンス。
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
- [Stream (Java SE 13 & JDK 13 )](https://docs.oracle.com/javase/jp/13/docs/api/java.base/java/util/stream/Stream.html)
|
110
|
+
|
111
|
+
- [IntStream (Java SE 13 & JDK 13 )](https://docs.oracle.com/javase/jp/13/docs/api/java.base/java/util/stream/IntStream.html)
|
1
追記
test
CHANGED
@@ -45,3 +45,53 @@
|
|
45
45
|
[1, 2, 3, 4, 5, 6]
|
46
46
|
|
47
47
|
```
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
案2
|
52
|
+
|
53
|
+
---
|
54
|
+
|
55
|
+
ちょっと読みづらいですけど、任意個数の結合にも対応できる例。
|
56
|
+
|
57
|
+
```Java
|
58
|
+
|
59
|
+
import java.util.*;
|
60
|
+
|
61
|
+
import java.util.stream.*;
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
class Main {
|
66
|
+
|
67
|
+
static int[] concat(int[]... arrs) {
|
68
|
+
|
69
|
+
return Stream.of(arrs).flatMapToInt(IntStream::of).toArray();
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
public static void main(String[] args) {
|
76
|
+
|
77
|
+
System.out.println(Arrays.toString(
|
78
|
+
|
79
|
+
concat(new int[]{1, 2, 3}, new int[]{4, 5, 6}, new int[]{7, 8, 9})
|
80
|
+
|
81
|
+
));
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/mdql7gB4guBIgUvl)
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
96
|
+
|
97
|
+
```
|