Bhaskar Mishra Bhaskar Mishra - 2 months ago 5x
Scala Question

Convert List[Double] to List[String]

I get a List of Double type from calling a function, I need to convert this List[Double] to List[String] for all elements. How can i do this? I tried using toString() but it fails.
My List Double :

List(153.0, 195.67, 212.33)

and when I try doing to convert it into using toString() it gives me an error as

type mismatch; found : List[Double] required: List[String]

my code looks like :

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

though on REPL it looks good to me.


You need to use and call toString:

NewFormat.getVal(, search,

Calling toString on a List[Double] will yield a String.