自定義可變長度二維陣列
阿新 • • 發佈:2019-01-27
</pre><pre name="code" class="java"> 體積:300ml 500ml 800ml 重量: 300g 500g 800g 體積重量 一級分類是確定個數 一級分類的二級分類是可變的 設計一個這種資料模式的二維陣列 private void initData(){ specificationList=DataView.modelList; //一級分類的個數 System.out.println("modelList size is: "+DataView.modelList.size()); if(DataView.modelList.size()!=0){ arrLevel1=new String[specificationList.size()]; arrLevel1Id=new String[specificationList.size()]; arrLevel2=new String[specificationList.size()][]; arrLevel2Id=new String[specificationList.size()][]; for(int i=0;i<specificationList.size();i++){ Iterator it=specificationList.get(i).keySet().iterator(); // Map modelMap=specificationList.get(i); while(it.hasNext()){ String key=(String) it.next(); System.out.println("key is: "+GoodsUtil.getKey(key)); arrLevel1[i]=GoodsUtil.getKey(key); arrLevel1Id[i]=GoodsUtil.getValue(key); ArrayList list=(ArrayList) specificationList.get(i).get(key); //每個 規格對應的list // System.out.println("list is: "+list.get(i)+"list.size()"+list.size()); arrLevel2[i]=new String[list.size()]; arrLevel2Id[i]=new String[list.size()]; for(int j=0;j<list.size();j++){ arrLevel2[i][j]=GoodsUtil.getKey(list.get(j).toString()); arrLevel2Id[i][j]=GoodsUtil.getValue(list.get(j).toString()); System.out.println("unitKey" +"i= "+i+" j= "+j+" "+ arrLevel2[i][j]); System.out.println("unitKey" +"i= "+i+" j= "+j+" "+ arrLevel2Id[i][j]); // } } } } }else{ arrLevel1=new String[0]; arrLevel1Id=new String[0]; arrLevel2=new String[0][0]; arrLevel2Id=new String[0][0]; } }