Remove object from ArrayList with some Object property

后端 未结 5 672
轻奢々
轻奢々 2020-12-06 12:06

I am maintaining one ArrayList of objects. And my object structure is Id, name, some other details. I need to remove one the object with some id value say(10) a

5条回答
  •  感情败类
    2020-12-06 12:51

    You could not do that without iterator, you should you Hashmap for this.

    public class ObjectStructure{
    private int Id;
    private String name;
    //and any data field you need
    }
    

    generate all setters and getters.

    Use this class in

    Hashmap data = new HashMap<>();
    

    you can add and delete data with only key which is Integer.

    data.remove(10);

提交回复
热议问题