var set = TreeSet(5,4,3,2,1) println(set) val diffSet: TreeSet[Int] = set // if I change above code to val diffSet: Set[Int] = set // the result is
Set does not guarantee ordering. Even if the underlying class is a TreeSet, if the expected result is a Set you'll loose the ordering in the first transformation you do.
Set
TreeSet
If you want ordering, do not use Set. I suggest, say, SortedSet.
SortedSet