从通用的arraylist中删除项目元素

1.使用Iterator移除元素

如:

Iterator itr = list.iterator();
    String strElement = "";
    while(itr.hasNext()){

      strElement = (String)itr.next();
      if(strElement.equals("2"))
      {
        itr.remove();
      }

2.如果在ArrayList中有你想要删除的对像,你要使用:

mArrayList.remove(object);

或者使用 Iterator来删除对象:

while(iterator.hasNext()){ if(iterator.next() == some condition for removal){ iterator.remove(); } } 

3.创建一个单独的ArrayList数据索引,以脱离原来的ArrayList,然后通过for循环遍历删除那些元素。

ArrayList<Myobj> arr = new ArrayList<Myobj>();
    for (Myobj o : arr){
    arr.remove(arr.indexOf(o))
     }

你可能感兴趣的:(从通用的arraylist中删除项目元素)