简体   繁体   English

嵌套LinkedList的.size()

[英].size() of a nested LinkedList

I have a nested LinkedList that I need to run through a loop and need the .size() of the nested list. 我有一个嵌套的LinkedList,需要循环运行,并且需要嵌套列表的.size()。 How can I access this nested list? 如何访问此嵌套列表? The outer list only has 1 element and that element has the number of elements I need to run the for loop. 外部列表只有1个元素,并且该元素具有运行for循环所需的元素数量。

 LinkedList<LinkedList<Plan>> eligiblePlansList = new LinkedList<>(); LinkedList<String> planNames = new LinkedList<>(); String [] arr; /** * Creates new form ComparePlansGUI */ public ComparePlansGUI() { initComponents(); } public ComparePlansGUI(HealthCare hc, Customer c){ this.hc = hc; eligiblePlansList.add(p.eligiblePlans(c, hc.getPlans())); for (int i = 0; i < eligiblePlansList.size(); i++){ planNames.add(i, eligiblePlansList.get(i).get(i).planName); } arr = planNames.toArray(new String[planNames.size()]); planNames.clear(); initComponents(); } 

尝试这个:

eligiblePlansList.get(0).size()
eligiblePlansList.get(0).size()

You need to add additional loop: 您需要添加其他循环:

for (int i = 0; i < eligiblePlansList.size(); i++) {
    LinkedList<Plan> planList = eligiblePlansList.get(i); // current list

    for (int j = 0; i < planList.size(); i++) {
        Plan plan = planList.get(j); // current plan
        planNames.add(i, plan.planName); 
    }
}

for(Linkedlist item:plans) 为(链接列表项目:计划)

for(plan p:item) 为(计划p:项目)

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

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