Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.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
Scala 将列表[双精度]转换为列表[字符串]_Scala - Fatal编程技术网

Scala 将列表[双精度]转换为列表[字符串]

Scala 将列表[双精度]转换为列表[字符串],scala,Scala,我通过调用一个函数得到一个双精度类型的列表,我需要将所有元素的这个列表[Double]转换为列表[String]。我该怎么做?我尝试使用toString(),但失败了。 我的名单是双重的: List(153.0, 195.67, 212.33) 当我尝试将它转换为使用toString()时,它会给我一个错误 type mismatch; found : List[Double] required: List[String] 我的代码如下所示: val apiRes = ApiRespons

我通过调用一个函数得到一个双精度类型的列表,我需要将所有元素的这个列表[Double]转换为列表[String]。我该怎么做?我尝试使用toString(),但失败了。 我的名单是双重的:

List(153.0, 195.67, 212.33) 
当我尝试将它转换为使用toString()时,它会给我一个错误

type mismatch; found : List[Double] required: List[String]
我的代码如下所示:

val apiRes = ApiResponse.fromAPI(search) //returns List of Double   
NewFormat.getVal(x.id, search,  apiPrices.toString) // Type Mismatch

尽管在REPL上,我觉得不错。

您需要使用
List.map
并调用
toString

NewFormat.getVal(x.id, search,  apiPrices.map(_.toString))
列表[Double]
上调用
toString
将生成一个
字符串