「Java」可変長引数を利用するサンプル
書式
void 関数名(String… 変数名)
使用例
package com.arkgame.strudy.java;
class User {
//可変長引数
static void show(int n, String... msg) {
for (String cft : msg) {
System.out.println(n + " " + cft);
}
}
}
public class Testgt {
public static void main(String[] args) {
User.show(21, "test01");
User.show(22, "BB02", "CC03");
User.show(23);
User.show(32, "DD02", "EE03", "FF04");
}
}
実行結果
21 test01
22 BB02
22 CC03
32 DD02
32 EE03
32 FF04