0
 List[String] = List(id:1, count:23331, id:3, count:34123, id:4, count:4021)

I have a list of string as above

I want the output to be below

 List((1,23331),(3,34123),(4,4021))

Scala Code :

 scala> val result = res11
 result: List[String] = List(id:1, count:23331, id:3, count:34123, id:4, count:4021)

 scala> result.map(elem => elem.split(":")(1))
 res12: List[String] = List(1, 23331, 3, 34123, 4, 4021)

Could someone help me to get the expected output

Surender Raja
  • 3,553
  • 8
  • 44
  • 80

1 Answers1

1
result.map(_.split(":")(1)).sliding(2,2).toList.map{case List(a,b) => (a,b)}
mop
  • 423
  • 2
  • 11