我的scala列表包含以下元素
val myList = List(List("A","B","C","E"),List("A","A1","B1","C","E"),List("P","E","L","A"))
现在我想找出上面列表中的不同元素,所以我的最终列表将是
val finalList = List ("A","E")
如何在scala中找到它?
答案 0 :(得分:10)
查找所有内部列表之间的交集:
myList.reduceLeft(_.intersect(_)) // List[String] = List(A, E)