If you want to detect any Map
:
for(element <- maps) {
if(element.isInstanceOf[Map[_, _]]) {
print("this is a collection instance ")
}
println(element)
}
But this didn't work because you check whole tuple ("s" -> 2 etc.) instead of second element of tuple:
for(element <- maps) {
if(element._2.isInstanceOf[Map[_, _]]) {
print("this is a collection instance ")
}
println(element._2)
}
Or with pattern matching:
for((_, v) <- maps) {
if(v.isInstanceOf[Map[_, _]]) {
print("this is a collection instance ")
}
println(v)
}
Or with even more pattern matching:
maps foreach {
case (_, v: Map[_, _]) => println("this is a collection instance " + v)
case (_, v) => println(v)
}