Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.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
String 如何使用SCALA将字符串转换为列表?_String_List_Scala - Fatal编程技术网

String 如何使用SCALA将字符串转换为列表?

String 如何使用SCALA将字符串转换为列表?,string,list,scala,String,List,Scala,我是Scala的新手,很难弄清楚这一点 我有这样一个字符串: a = "The dog crossed the street" 我想创建一个如下所示的列表: a = List("The","dog","crossed","the","street") 我尝试使用.split(“”)执行此操作,然后返回它,但它似乎什么也不做,返回相同的字符串。有人能帮我吗 在一个或多个空白字

我是Scala的新手,很难弄清楚这一点

我有这样一个字符串:

a = "The dog crossed the street"
我想创建一个如下所示的列表:

a = List("The","dog","crossed","the","street")
我尝试使用.split(“”)执行此操作,然后返回它,但它似乎什么也不做,返回相同的字符串。有人能帮我吗

  • 在一个或多个空白字符上使用
    split()
    更安全,以防组合中有任何制表符或相邻空格
  • split()
  • 无法复制:
    "The dog\tcrossed\nthe      street".split("\\s+").toList
    //res0: List[String] = List(The, dog, crossed, the, street)