Neo-coder
Neo-coder

Reputation: 7840

Scala list of list String find distinct elements

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

Answers (1)

Sergii Lagutin
Sergii Lagutin

Reputation: 10671

Find intersection between all inner lists:

myList.reduceLeft(_.intersect(_))  // List[String] = List(A, E)

Upvotes: 10

Related Questions