[ACCEPTED]-The difference between Lists and Sets-scala-collections
Accepted answer
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)
The main difference in terms of functionality 3 is the fact that Set
s cannot contain duplicate 2 elements.
Adding to collection where the 1 element already exists yields no effect.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.