我有一個嵌套的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(); }
eligiblePlansList.get(i).size()will do – hoaz
約定接受一個答案,如果他們中的任何一個人幫了你的忙。 – timeshift117