[英]How to convert String Iterator into List of Tuples
How can 怎么能
val s = Iterator("a|b|2","a|c|3")
be converted to 被转换为
List( (("a" , "b") , 2) , (("a" , "c") , 3)))
This is my current progress : 这是我目前的进展:
val v = s.map(m => m.split("|")(0))
How can I parse the String into its constituent parts so can be converted to a List of Tuples ? 如何将String解析为其组成部分,以便转换为元组列表?
您可以匹配从split
返回的数组:
val v = s.map(_.split('|') match { case Array(a, b, n) => ((a, b), n.toInt) })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.