回答編集履歴
1
追記
test
CHANGED
@@ -3,3 +3,47 @@
|
|
3
3
|
setLine({new String[] { "Hello","World" }});
|
4
4
|
|
5
5
|
```
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
かぶったので変化球。[List#of()](https://docs.oracle.com/javase/jp/11/docs/api/java.base/java/util/List.html#of(E...))のように、メソッド定義を可変長引数にする手もある。
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
```java
|
14
|
+
|
15
|
+
public class Test {
|
16
|
+
|
17
|
+
String s = "";
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
public static void main(String[] args) {
|
22
|
+
|
23
|
+
new Test();
|
24
|
+
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
Test() {
|
30
|
+
|
31
|
+
setLine("Hello", "World");
|
32
|
+
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
void setLine(String... st) {//配列を要求
|
38
|
+
|
39
|
+
for (String a : st) {
|
40
|
+
|
41
|
+
s += a + " ";
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
```
|