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");
println(vege);
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.
Cool...
For example :
val vege = Set("Radish","Carrot","Carrot","Potato");
println(vege);
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.
Cool...
No comments:
Post a Comment