How to remove multiple elements from a set based on a condition in Kotlin

1 Answer

0 votes
fun main() {
   	val mutableSet = mutableSetOf(1, 2, 3, 4, 5)
	
    mutableSet.removeIf { it > 2 } 
	
    println(mutableSet) 
}

 
  
/*
run:

[1, 2]

*/

 



answered Aug 6, 2025 by avibootz

Related questions

1 answer 75 views
2 answers 99 views
1 answer 157 views
1 answer 218 views
1 answer 198 views
...