Quantcast
Channel: alvinalexander.com - sequence
Viewing all articles
Browse latest Browse all 25

Scala - How to find the unique items in a List, Array, Vector (sequence)

$
0
0

Scala FAQ: How do I find the unique items in a List, Array, Vector, or other Scala sequence?

Use the distinct method. Here's a simple example using a List of integers:

scala> val x = List(1,1,1,2,2,3,3)
x: List[Int] = List(1, 1, 1, 2, 2, 3, 3)

scala> x.distinct
res0: List[Int] = List(1, 2, 3)

As you can see, res0 now contains only the unique elements in the list.

read more


Viewing all articles
Browse latest Browse all 25

Trending Articles