Accepted answer

Here is the code i have tried and it worked:


which gives the output:

upper: List[Array[Array[String]]] = List(Array(Array(a, bc), Array(de, f)), Array(Array(uvw), Array(xy, z)), Array(Array(123), Array(456)))


Using>x.split(":")) will give you a list of Array.

upper: List[Array[String]] = List(Array(a;bc, de;f), Array(uvw, xy;z), Array(123, 456))

Mapping afterwards, you can see that the item will be an array where you are trying to run split on.

You might useflatMap instead which will first give you List(a;bc, de;f, uvw, xy;z, 123, 456) and then you can use map on those items splitting on ;

val upper = list.flatMap(_.split(":")).map(_.split(";"))


upper: List[Array[String]] = List(Array(a, bc), Array(de, f), Array(uvw), Array(xy, z), Array(123), Array(456))


You can use split with multiple delimiters in one map iteration :

val upper = => x.split("[:;]"))

//upper: List[Array[String]] = List(Array(a, bc, de, f), Array(uvw, xy, z), Array(123, 456))

Related Query

More Query from same tag