Its unclear what you want. What output are you expecting?
Do you want to print the second item of data1
?
println(data1._2)
Or print each item of the buff in data1
?
data1._2.foreach(m => println(m))
Do you want for data1 to be a collection of tuples and to map over that?
import scala.collection.mutable.ArrayBuffer
val data1 = Vector(("" , ArrayBuffer(("", 1))), ("", ArrayBuffer("", 1)))
data1.foreach { case (a,b) => println(b) }
Note that if you're just printing stuff out, you want foreach
, not map
.
Based on your edits:
import scala.collection.mutable.ArrayBuffer
val data1 = (("", ArrayBuffer(("a", 1), ("b", 1), ("a", 1))))
val grouped = data1._2.groupBy(_._1).map { case (k, vs) => (k, vs.map(_._2).sum) }
// Map(b -> 1, a -> 2)