Home » Scala ListSet

Scala ListSet

In scala, ListSet class implements immutable sets using a list-based data structure. Elements are stored internally in reversed insertion order, which means the newest element is at the head of the list. It maintains insertion order.

This collection is suitable only for a small number of elements. You can create empty ListSet either by calling the constructor or by applying the function ListSet.empty. Its iterate and traversal methods visit elements in the same order in which they were first inserted.


Scala ListSet Example

Output:

4   2   8   0   6   3   45  

Scala ListSet Example: Creating ListSet and Adding Elements

Output:

listset: ListSet()  listset2: ListSet()  After adding new elements:  listset: ListSet(India)  listset2: ListSet(Russia)  
Next TopicScala Seq

You may also like