Skip to content

kotlin basics : Using Set in the code

Devrath edited this page Dec 24, 2023 · 1 revision

About Set

  • This is a type of collection that holds only a unique collection of items.
  • Distinctions from other elements are what make it unique.
  • We use set to store and process the elements.
  • Processing the elements is done in a loop.
  • We can check if the element exists in a set.
  • If we want to add new element or remove the element from the set only if we use mutableSet(), This is similar to other collections.
private fun initiate() {
        var students = setOf("Mahesh","Suresh","Venkatesh","Mahesh")
        println(students)
        println(students.contains("Suresh"))
}
Clone this wiki locally