简体   繁体   English

访问子元素<list> pojo class</list>

[英]accessing child elements of <List>pojo class

i created an Employee list of POJO.我创建了一个 POJO 的员工列表。

public class Employee 
{   public String name; 
    public String Key; 
    private string Value; 
getters and setters.
}

another class另一个 class

I am adding condition that if employee childelements /Key size()is <=4 then implement this code.我正在添加条件,如果员工子元素 /Key size()is <=4 然后实现此代码。

I tried doing this if(getemployee().getkey().size() <= 4){ do something}我试过这样做if(getemployee().getkey().size() <= 4){ do something}

issue getkey() is string.问题 getkey() 是字符串。 edited here.在这里编辑。
rookie mistake.since its a forloop.菜鸟错误。因为它是一个forloop。 i did count.to limit if(count<=4).我确实 count.to 限制 if(count<=4)。 Thanks in advance, my apology for syntax i typed very quick.在此先感谢,我对语法的道歉我输入得很快。

You need to have a structure like the one given below:您需要具有如下所示的结构:

public class Parent{
    List<Employee> employees = new ArrayList<Employee>();
    public void setEmployees(List<Employee> employees){
        this.employees = employees;
    }
    public List<Employee> getEmployees(){
        return employees;
    }
    //...
}

Then, you can do like然后,你可以这样做

Parent p = new Parent();
if(p.getEmployees().size() <= 4) {
    //do something
}

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

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