-
Couldn't load subscription status.
- Fork 24
kotlin basics : Using Set in the code
Devrath edited this page Dec 24, 2023
·
1 revision
- This is a type of collection that holds only a
unique collectionof items. - Distinctions from other elements are what make it unique.
- We use set to
storeandprocessthe 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 elementorremove the elementfrom thesetonly if we usemutableSet(), This is similar to other collections.
private fun initiate() {
var students = setOf("Mahesh","Suresh","Venkatesh","Mahesh")
println(students)
println(students.contains("Suresh"))
}