熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

JAVA中HashMap(哈希表)的使用(List)方法

2022-06-13   來源: Java核心技術 

  當hashMap的key是多個字段且想得到多個value時可能將key和 value分別做成List
      

  view plaincopy to clipboardprint?
    import javautilMap;

  //inquiry result
    List fromDetailList = instHdDaoretrieveInstInfoByView(sysOwnerCd fromCd instruct);

  // Initial Value
    Integer dtTotalTruck = ;
    Integer dtTotalQuantity = ;

  Map hm = new HashMap();

  Iterator it = erator();
    while(ithasNext()){
        MeInstHd meInstHd = (MeInstHd)itnext();

  List arr = new ArrayList();
        List arr = new ArrayList();
        List arr = new ArrayList();

  String carrierCd = meInstHdgetCarrCd()trim();

  arradd(carrierCd); // put keyValue to Arr

  if(ntainsKey(arr)){
            // carrierCd is exist in hm
            arr = (ArrayList)hmget(arr); // 通過Key arr取得arr的Value arrList arr中有2列值他們分別是dtTotalQuantity 和dtTotalTruck

  dtTotalQuantity = (Integer)arrget() ;
            dtTotalQuantity += meInstHdsumInstructQty();
            dtTotalTruck = (Integer)arrget() ;
            dtTotalTruck += ;

  arradd(dtTotalQuantity);
            arradd(dtTotalTruck);

  hmput(arr arr); // creat hashMap hm
        }
        else{
            // carrierCd is not exist in hm
            arradd(meInstHdsumInstructQty()); //put value to arr
            arradd(); // dtTotalTruck initial value is

  hmput(arrarr); // 其中arr是keyarr是value可以通過get(arr)來取得其value
        }
    }


From:http://tw.wingwit.com/Article/program/Java/hx/201311/27090.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.