androidlistkotlinremoveall

How to remove certain values in list but that value occurs more than one?


Let's say I have

val asd = mutableListOf("lulu","bubu","gugu","bubu")

If I use asd.remove("bubu"), it only removes the first bubu.

How to remove all bubu in asd without a loop?


Solution

  • You can use removeAll function that takes Collection as input which is array-List of string in this case. It will remove all occurences of all elements present in the parameter.

    asd.removeAll(mutableListOf("bubu"))
    

    Use this code and it should work now.