Tuesday, July 8, 2014

What Happens When Scala Set Contains Duplicate Elements

Set is a collection of non duplicate items.  In Scala also the concept is similar.  So what happens when you have a Set defined with duplicate items.

For example : 

    val vege = Set("Radish","Carrot","Carrot","Potato");

You may expect the compiler to complain since Carrot occurs twice in the Set.  However see the result below on what happens -

Set(Radish, Carrot, Potato)

It simply means that Scala ignores the duplicate entry in the Set and does not complain.


No comments:

Post a Comment