How to remove specific object from ArrayList in Java?

前端 未结 13 1664
旧时难觅i
旧时难觅i 2020-12-05 06:54

How can I remove specific object from ArrayList? Suppose I have a class as below:

import java.util.ArrayList;    
public class ArrayTest {
    int i;

    pu         


        
13条回答
  •  醉话见心
    2020-12-05 07:47

    If you want to remove multiple objects that are matching to the property try this.

    I have used following code to remove element from object array it helped me.

    In general an object can be removed in two ways from an ArrayList (or generally any List), by index (remove(int)) and by object (remove(Object)).

    some time for you arrayList.remove(index)or arrayList.remove(obj.get(index)) using these lines may not work try to use following code.

    for (Iterator iter = detailInboxArray.iterator(); iter.hasNext(); ) {
        DetailInbox element = iter.next();
       if (element.isSelected()) {
          iter.remove();
       }
    }
    

提交回复
热议问题