Following is the syntax for working with sets :
// Creating an empty Set
emptySet</* Type */>()
// Creating a (immutable) set of elements
setOf(/* Elements */)
// Creating a MutableSet of elements
mutableSetOf(/* Elements */)
// Create a set from list or array
list/array.toSet()
// Create a MutableSet from list or array
list/array.toMutableSet()
// Printing a set
println(set)
// Check if an element exists in set
set.contains(/* element */)
// Adding an element to set
set.add(/* element */)
// Removing an element from set
set.remove(/* element */)
Note that set
does not have index based operations because order is not mainatained in a set
.