How to remove element from ArrayList by checking its value?

后端 未结 11 1191
一整个雨季
一整个雨季 2020-12-01 03:47

I have ArrayList, from which I want to remove an element which has particular value...

for eg.

ArrayList a=new ArrayList         


        
11条回答
  •  独厮守ぢ
    2020-12-01 04:03

    Just use myList.remove(myObject).

    It uses the equals method of the class. See http://docs.oracle.com/javase/6/docs/api/java/util/List.html#remove(java.lang.Object)

    BTW, if you have more complex things to do, you should check out the guava library that has dozen of utility to do that with predicates and so on.

提交回复
热议问题