简体   繁体   中英

How to filter pojo class and make new pojo class from them

I have one POJO class . ContactPOJO.class

 @PrimaryKey(autoGenerate = true)
    private  int id;
    private  String contact_id;
    private  String contact_name;
    private  String contact_number;
    private  boolean is_selected;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getContact_id() {
        return contact_id;
    }

    public void setContact_id(String contact_id) {
        this.contact_id = contact_id;
    }


    public boolean isIs_selected() {
        return is_selected;
    }

    public void setIs_selected(boolean is_selected) {
        this.is_selected = is_selected;
    }

    public String getContact_name() {
        return contact_name;
    }

    public void setContact_name(String contact_name) {
        this.contact_name = contact_name;
    }

    public String getContact_number() {
        return contact_number;
    }

    public void setContact_number(String contact_number) {
        this.contact_number = contact_number;
    }

Now I have to make new POJO class but only for that which is_selected boolean value is true in ContactPOJO. I don't know how to do that . Any help would be appreciate.Thanks in advance

EDIT: I have List<ContactPOJO> list_contact . Which contains all contacts from phone . Now some of them will be selected ,some of them will be not . its selected or not will be stored in is_selected variable . now I have to make new list .lets say List<newContactPOJO> . but it will contain only is_selected true value from that old one.

List<ContactPOJO> list_contact;
List<ContactPOJO> list_selected_contact = new ArrayList();
for (ContactPOJO pojo : list_contact){
    pojo.setIs_selected(true);
    list_selected_contact.add(pojo);
}

==> now you have a new list with all selected object

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM