Suppose I have
val dirty = List(\"a\", \"b\", \"a\", \"c\")
Is there a list operation that returns \"a\", \"b\", \"c\"
Have a look at the ScalaDoc for Seq,
scala> dirty.distinct
res0: List[java.lang.String] = List(a, b, c)
Update. Others have suggested using Set
rather than List
. That's fine, but be aware that by default, the Set
interface doesn't preserve element order. You may want to use a Set implementation that explicitly does preserve order, such as collection.mutable.LinkedHashSet.
inArr.distinct foreach println _