2014-02-14 44 views
0

我有一個嵌套的LinkedList,我需要通過循環運行並需要嵌套列表的.size()。我怎樣才能訪問這個嵌套列表?外部列表只有1個元素,並且該元素具有運行for循環所需的元素數量。.size()嵌套LinkedList

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(); 
} 
+0

eligiblePlansList.get(i).size()will do – hoaz

+0

約定接受一個答案,如果他們中的任何一個人幫了你的忙。 – timeshift117

回答

0

試試這個:

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

這工作!謝謝你的幫助! – user3310536

0

您需要添加額外的循環:

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); 
    } 
} 
0

爲(LinkedList的項目:計劃)

for(plan p:item)