Deleting objects from an ArrayList in Java

前端 未结 13 1961
轮回少年
轮回少年 2020-12-15 03:14

I need to delete some objects from an ArrayList if they meet a condition and I\'m wondering which way could be more efficient.

Here\'s the situation: I

13条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 03:59

    I have found an alternative faster solution:

      int j = 0;
      for (Iterator i = list.listIterator(); i.hasNext(); ) {
        j++;
    
        if (campo.getNome().equals(key)) {
           i.remove();
           i = list.listIterator(j);
        }
      }
    

提交回复
热议问题