I have a l: List[Char] of characters which I want to concat and return as a String in one for loop.
I tried this
val x: String = for(i <- list) yield(i) leading to
error: type mismatch; found : List[Char] required: String So how can I change the result type of yield?
Thanks!
Try this:
val x: String = list.mkString This syntax:
for (i <- list) yield i is syntactic sugar for:
list.map(i => i) and will thus return an unchanged copy of your original list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With