October 2018
Intermediate to advanced
370 pages
9h 15m
English
A mutable set is an extension of a set that supports adding and removing elements. Like a set, a mutable set does not provide its own function, but it does extend two interfaces: set and mutableCollection. Mutable sets also override all functions from their parent interfaces. This means that we can use all functions, including size, isEmpty, add, contains, and retainAll:
fun mutableSetFunction() { val mutableSetItems : MutableSet<Int> = mutableSetOf(1,1,2,3,3,4,5,5) var mutableSetIterator = mutableSetItems.iterator() while (mutableSetIterator.hasNext()) { print(mutableSetIterator.next()) } println("") println("Set size ${mutableSetItems.size}") var item = 5 var result = mutableSetItems.contains(item) println("Mutable item ...Read now
Unlock full access