Here we use toSet and toList to strip duplicate Ints. We create a list that has six Ints, and two duplicate Ints. We then remove those duplicates.
object Program {
def main(args: Array[String]): Unit = {
// Create a list of Ints.
val ids = List(10, 10, 1, 2, 3, 3)
println(ids)
// Convert list to set.
// ... Duplicate elements are removed at this step.
val set = ids.toSet
println(set)
// Convert set to list.
val ids2 = set.toList
println(ids2)
}
}
List(10, 10, 1, 2, 3, 3)
Set(10, 1, 2, 3)
List(10, 1, 2, 3)