[ACCEPTED]-The difference between Lists and Sets-scala-collections

Accepted answer
Score: 11

A Set is unordered and can't have duplicate 3 items.

scala> Set(1,2,3,1,2,3) == Set(3,2,1)
res2: Boolean = true

Sequences (Array, List, Vector, etc) are ordered 2 and can have repeated elements.

To use your 1 example (which, incidentally, doesn't compile...):

val stuff = Array(1, 2, 3, 4)
val apple = Set(1, 2, 3, 4)

stuff.map(x => x % 3)  // Array(1, 2, 0, 1)
apple.map(x => x % 3)  // Set(1, 2, 0)
Score: 4

The main difference in terms of functionality 3 is the fact that Sets cannot contain duplicate 2 elements.

Adding to collection where the 1 element already exists yields no effect.

More Related questions