Given List:
val myList = List(
"IDENTIFIER, a, b, c",
"IDENTIFIER, d, e, f",
"INFORMATION, a, b, c",
"INFORMATION, d, e, f"
)
Using,
myList.map(_.split(",")).groupBy(_.head).mapValues(_.map(_.tail.mkString(" ").trim))
In Scala REPL:
scala> myList.map(_.split(",")).groupBy(_.head).mapValues(_.map(_.tail.mkString(" ").trim))
res91: scala.collection.immutable.Map[String,List[String]] = Map(IDENTIFIER -> List(a b c, d e f), INFORMATION -> List(a
b c, d e f))
scala>
0
solved Scala groupBy to map from list [closed]