Kotlin Collections – Sets

Using Sets in Kotlin.

// Similar to Lists except no duplicate items
// setOf and immutableSetOf functions
fun main() {
    val setInts = setOf(10, 15, 19, 5, 3, -22)
    println(setInts.plus(20)) // Prints out set incl 20 but does not change Set as is immutable
    println(setInts.plus(10)) // Can't contain duplicates, so original Set printed
    println(setInts.minus(19))
    println(setInts.minus(100)) // Nothing happens as 100 not a value
    println(setInts.average()) // Result is Double
    println(setInts.drop(3)) // Drops the 1st 3 elements of the Set
    println("======")

    val mutableInts = mutableSetOf(1, 2, 3, 4, 5)
    mutableInts.plus(10) // Does not add an element, just returns a result, like minus function
    println(mutableInts)

}