sarthak sarthak - 1 month ago 6
Scala Question

Error while trying to Iterate over List of Strings

I have an RDD of form

(String,(Int,Iterable[String]))
. I am trying to check if the string "Bethan" is a part of the
Iterable[String]
. I wrote the following line in scala:

val disOneRdd = disRdd.map(x=> {if(x._2._2.contains("Bethan")) (x._1,(1,x._2._2)) else x})


But I am getting the following error:

value contains is not a member of Iterable[String].


How can I check if the string is present in the list or not?

Answer

Convert to list:

val disOneRdd = disRdd.map(x=> {if(x._2._2.toList.contains("Bethan")) ... })