回答編集履歴
2
リンクの追加
answer
CHANGED
@@ -46,4 +46,11 @@
|
|
46
46
|
**実行結果** [Wandbox](https://wandbox.org/permlink/mdql7gB4guBIgUvl)
|
47
47
|
```
|
48
48
|
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
49
|
-
```
|
49
|
+
```
|
50
|
+
|
51
|
+
参考
|
52
|
+
---
|
53
|
+
安定の公式リファレンス。
|
54
|
+
|
55
|
+
- [Stream (Java SE 13 & JDK 13 )](https://docs.oracle.com/javase/jp/13/docs/api/java.base/java/util/stream/Stream.html)
|
56
|
+
- [IntStream (Java SE 13 & JDK 13 )](https://docs.oracle.com/javase/jp/13/docs/api/java.base/java/util/stream/IntStream.html)
|
1
追記
answer
CHANGED
@@ -21,4 +21,29 @@
|
|
21
21
|
**実行結果** [Wandbox](https://wandbox.org/permlink/suoFynUMjA0f1d3M)
|
22
22
|
```
|
23
23
|
[1, 2, 3, 4, 5, 6]
|
24
|
+
```
|
25
|
+
|
26
|
+
案2
|
27
|
+
---
|
28
|
+
ちょっと読みづらいですけど、任意個数の結合にも対応できる例。
|
29
|
+
```Java
|
30
|
+
import java.util.*;
|
31
|
+
import java.util.stream.*;
|
32
|
+
|
33
|
+
class Main {
|
34
|
+
static int[] concat(int[]... arrs) {
|
35
|
+
return Stream.of(arrs).flatMapToInt(IntStream::of).toArray();
|
36
|
+
}
|
37
|
+
|
38
|
+
public static void main(String[] args) {
|
39
|
+
System.out.println(Arrays.toString(
|
40
|
+
concat(new int[]{1, 2, 3}, new int[]{4, 5, 6}, new int[]{7, 8, 9})
|
41
|
+
));
|
42
|
+
}
|
43
|
+
}
|
44
|
+
```
|
45
|
+
|
46
|
+
**実行結果** [Wandbox](https://wandbox.org/permlink/mdql7gB4guBIgUvl)
|
47
|
+
```
|
48
|
+
[1, 2, 3, 4, 5, 6, 7, 8, 9]
|
24
49
|
```
|