lkn2993
lkn2993

Reputation: 566

Scala make List of strings from char array

Here's what I'm trying to do:

val StringSpace = charList.reduce(_ + _ + _ + _ + " ")
val StringList = //Tokenize StringSpace with " "

but it returns missing parameter type within first line.

So how can someone actually join lists into half or quarter size in scala?

e.g: From

List ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h")

To:

List("abcd", "efgh")

Upvotes: 0

Views: 659

Answers (2)

dcastro
dcastro

Reputation: 68640

val l = List ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h")
l.grouped(4).map(_.mkString)

Upvotes: 3

Odomontois
Odomontois

Reputation: 16308

charList.grouped(4).map(_.mkString).toList

Upvotes: 1

Related Questions