Find elements in a list that are not in the second list (in scala)

前端 未结 3 1584
既然无缘
既然无缘 2021-02-12 09:32

Suppose I have two lists:

val a = List(\'a\', \'b\', \'c\')
val b = List(\'a\', \'b\', \'c\', \'d\')

I want to get the element which is not in

3条回答
  •  無奈伤痛
    2021-02-12 10:21

    You can use diff for this:

    scala> b diff a
    res1: List[Char] = List(d)
    

    You probably want to work with Set if you are doing diff.

提交回复
热议问题