How to remove specific object from ArrayList in Java?

前端 未结 13 1605
旧时难觅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 08:00
    List<Object> list = new ArrayList();
    for (Iterator<Object> iterator = list.iterator(); iterator.hasNext();) {
      Object obj= iterator.next();
        if (obj.getId().equals("1")) {
           // Remove the current element from the iterator and the list.
           iterator.remove();
        }
    }
    
    0 讨论(0)
提交回复
热议问题