How do I remove an object from an ArrayList in Java?

后端 未结 9 1656
面向向阳花
面向向阳花 2020-12-15 01:06

I have an ArrayList that contains some object, such as User, and each object has a name and password property. How can I

9条回答
  •  庸人自扰
    2020-12-15 01:11

    Iterator it = list.iterator();
    while (it.hasNext()) {
      User user = it.next();
      if (user.getName().equals("John Doe")) {
        it.remove();
      }
    }
    

提交回复
热议问题