‫Welcome back.
‫In this video we're going to learn about another type of collections which is the set.
‫A set is a collection of unordered unique elements.
‫There are no duplicate elements.
‫The order of set elements doesn't have a significant effect.
‫I'll start with the immutable sets.
‫An immutable set in Kotlin is a collection of unique elements that cannot be modified after it's created.
‫Immutable sets ensure that their contents remain constant and they do not allow duplicate elements.
‫You can use immutable sets when you need to store a fixed set of distinct elements, and you want to
‫prevent any changes to that set.
‫Elements.
‫Immutable sets are created using the set of or set of not null functions.
‫In Kotlin's standard library, I'll start using the set of function val colors equals to set of function.
‫Here you can specify the generic type or whenever you put any element, you can get rid of this generic
‫type because it will detect the type of these elements.
‫Red.
‫Green.
‫Blue.
‫This function the set of function allowing you to specify the elements you want to include.
‫The resulting set is read only and doesn't allow duplicate elements.
‫In this example, the color set is immutable and you can't add, remove, or modify elements in it after
‫creation.
‫It contains the specified colors and each element is unique.
‫Within the set.
‫You can access elements in an immutable set by iterating over the set, or by checking for the presence
‫of specific elements.
‫Immutable sets are useful in scenarios where you need to maintain a fixed set of unique values that
‫should not change throughout your program's execution.
‫In the same way of what we've done in the lists, I can iterate through the elements in the set by using
‫the for loop so every element inside colors immutable set.
‫Go and print this item.
‫Run the program.
‫And here we get all the elements of this set.
‫If you need to modify a set, you should use a mutable set created with functions like mutable set of,
‫which allows you to add and remove elements.
‫And this is what we're going to learn in the next video.