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 87 views
2 answers 118 views
1 answer 175 views
1 answer 233 views
1 answer 225 views
...