Remove object from ArrayList with some Object property

后端 未结 5 684
轻奢々
轻奢々 2020-12-06 12:06

I am maintaining one ArrayList of objects. And my object structure is Id, name, some other details. I need to remove one the object with some id value say(10) a

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-06 13:00

    If you really do not want to iterate over the list, you could use a stream but I personnally prefer Collection#removeIf like @TagirValeev suggested

    myList = myList.stream()
                   .filter(x -> x.id() != 10)
                   .collect(Collectors.toList());
    

提交回复
热议问题