Reputation: 7840
Hi my scala list contains following elements
val myList = List(List("A","B","C","E"),List("A","A1","B1","C","E"),List("P","E","L","A"))
now I want to find out distinct elements from above list so my final list will be
val finalList = List ("A","E")
How this find out in scala ?
Upvotes: 1
Views: 598
Reputation: 10671
Find intersection between all inner lists:
myList.reduceLeft(_.intersect(_)) // List[String] = List(A, E)
Upvotes: 10