score:0

Accepted answer

Here is the code i have tried and it worked:

val upper=list.map(x=>x.split(":")).map(x=>x.map(x=>x.split(";")))

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)))

score:2

Using list.map(x=>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(";"))

Output

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

score:2

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

val upper = list.map(x => 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