简体   繁体   中英

.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. 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.

 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)

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