我正在使用Apache Commons CLI,我的用例是带有一些选项的可变数量的参数。
举个例子:
-p str1 str2;
它可以实现
-p str1 str2 str3 .. strn
另外一种是:
-m str1
-h
使用
cmdline.getOptionValues("p");
它只获取最后一个字符串。如何获取特定选项的所有值?
编辑:
if(cmdline.hasOption("p")){
String[] argsList = cmdline.getOptionValues(p);
String strLine = Arrays.toString(argsList);
argsList = strLine.split(",");
}
我这样做对吗?字符串中是否只包含我想要的数据,或者会有意外的空格或其他东西?