Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 从Scala中的命令行参数创建列表_List_Scala_Command Line Arguments - Fatal编程技术网

List 从Scala中的命令行参数创建列表

List 从Scala中的命令行参数创建列表,list,scala,command-line-arguments,List,Scala,Command Line Arguments,在scala main方法中,我使用import org.apache.commons.cli.{BasicParser,Options}来解析命令行参数。其中一个参数是逗号分隔的字符串,它列出了我要运行的方法 我有一个映射,它将字符串映射到方法,例如 val methods = Map("first" -> first, "second" -> second, "third" -> third) 现在,我想从命令行arg创建一个要运行的方法列表。i、 e.如果我将arg作为

在scala main方法中,我使用
import org.apache.commons.cli.{BasicParser,Options}
来解析命令行参数。其中一个参数是逗号分隔的字符串,它列出了我要运行的方法

我有一个映射,它将字符串映射到方法,例如

val methods = Map("first" -> first, "second" -> second, "third" -> third)
现在,我想从命令行arg创建一个要运行的方法列表。i、 e.如果我将arg作为
“first,second”
,列表应包含
列表(first,second)
,但如果我将arg作为
“first,third”
,列表应包含
列表(first,third)

我知道列表是不可变的,所以我不能迭代和添加


< P> > Scala的方法是什么?

< P>假设CLI用逗号分隔的单词传递字符串,考虑将这样的兴趣子串分隔开来,

val methodNames = "first,second".split(",").toList
val methodNames = "first,second".split("\\W+").toList
或者像这样把单词分开

val methodNames = "first,second".split(",").toList
val methodNames = "first,second".split("\\W+").toList
因此,要从列表中获取方法,请考虑

methodsNames.map(methods)

但这会创建一个字符串列表(拆分本身就是这样做的)。我想要一个方法列表,其中的方法是从映射中获取的。@navinpai note更新到获取方法的问题和添加到答案。第一、第二、…,的类型是什么?