简体   繁体   English

如何过滤pojo类并从中创建新的pojo类

[英]How to filter pojo class and make new pojo class from them

I have one POJO class . 我有一堂POJO课。 ContactPOJO.class 联系POJO.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. 现在,我必须创建新的POJO类,但仅对于在ContactPOJO中is_selected布尔值为true的类。 I don't know how to do that . 我不知道该怎么做。 Any help would be appreciate.Thanks in advance 任何帮助将不胜感激。

EDIT: I have List<ContactPOJO> list_contact . 编辑:我有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 . 其选择与否将存储在is_selected变量中。 now I have to make new list .lets say List<newContactPOJO> . 现在我必须创建一个新列表.lets说List<newContactPOJO> but it will contain only is_selected true value from that old one. 但它将仅包含旧版本中的is_selected真实值。

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 ==>现在您有了一个包含所有选定对象的新列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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