Rakshi Rakshi - 1 year ago 115
Android Question

How to remove items from generic arraylist in Android (Java)

I have a generic arraylist of an object here I want to remove certain elements, The problem is when I iterate the list with for loop, I can't do a simple sequence of

's because the elements are shifted after each removal.


Answer Source

Use Iterator to remove element


Iterator itr = list.iterator();
String strElement = "";
while (itr.hasNext()) {
    strElement = (String) itr.next();
    if (strElement.equals("2")) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download