How to remove multiple elements from a set in Scala

2 Answers

0 votes
val set = Set(1, 2, 3, 4)
val updatedSet = set -- Set(2, 3)

println(updatedSet) 
 
 
 
/*
run:
  
Set(1, 4)
  
*/

 



answered Aug 6, 2025 by avibootz
0 votes
import scala.collection.mutable.Set
 
val mutableSet = Set(1, 2, 3, 4)
mutableSet --= Set(1, 3)
 
println(mutableSet) 
 
 
 
/*
run:
  
HashSet(2, 4)
  
*/

 

 



answered Aug 6, 2025 by avibootz
...