Let us see Set in detail

- Set is iterable which contain unique elements (no duplicates)
- As duplicates are not allowed, there is no length (Seq have both length and index)
- Even though we can access data using index, it might not return same value always
- By default Set is immutable, but there is mutable one as well
- Here is the link for official documentation – http://docs.scala-lang.org/overviews/collections/sets
- Let us see how we can use mutable and immutable Set in a demo
- If the Set contain elements for which implicit Ordering defined, we can use SortedSet to sort the data
**Tests**`contains`

,`apply`

,`subsetOf`

. The`contains`

method asks whether a set contains a given element. The`apply`

method for a set is the same as`contains`

, so`set(elem)`

is the same as`set contains elem`

. That means sets can also be used as test functions that return true for the elements they contain.**Additions**`+`

and`++`

, which add one or more elements to a set, yielding a new set.**Removals**`-`

,`--`

, which remove one or more elements from a set, yielding a new set.- Let us create case class Order

**Additions**and**Removals**to mutable sets can be performed using +=, ++=, -= and –=

**Set operations**for union, intersection, and set difference. Each of these operations exists in two forms: alphabetic and symbolic. The alphabetic versions are`intersect`

,`union`

, and`diff`

, whereas the symbolic versions are`&`

,`|`

, and`&~`

. In fact, the`++`

that Set inherits from`Traversable`

can be seen as yet another alias of`union`

or`|`

, except that`++`

takes a`Traversable`

argument whereas`union`

and`|`

take sets.

## Start the discussion at discuss.itversity.com