How to remove all the occurrences of an item from a list in Scala

1 Answer

0 votes
object RemoveAllOccurrencesOfAnItemFromAList_Scala {
  def main(args: Array[String]): Unit = {
    var numbers = List(0, 1, 2, 2, 3, 4, 6, 2, 7, 8, 2, 2)
    
    numbers = numbers.filter(_ != 2)
    
    println(numbers)
  }
}

  
  
/*
run:
  
List(0, 1, 3, 4, 6, 7, 8)
  
*/

 



answered Oct 12, 2024 by avibootz
...