Hashmap question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • panos100m
    New Member
    • Aug 2007
    • 23

    #1

    Hashmap question

    Hi

    these are the conents of my hashmap printing out the entrySet.


    entrySet1: OrderDate=10/30/2007,
    entrySet2: Level_0={Item_0 ={ItemTotal= 3.99, ItemName=test® in, ShipDate=10/31/2007, ItemPrice= 3.99, ItemNumber=8504 , ItemQuantity=1} , ShipMethodID=75 , ItemCount=1, Items_StatusID= 2, Items_Status=Sh ipped, ShipMethod=, Tracking_Tracki ngNumber=, ShippingLevelID =1}
    entrySet3: Outcome={Return Code=0, ReturnMessage}


    entryset3 is another hashmap and i retieve its contents by doing

    Map outcome= (Map) muhamainhashmap name.get("Outco me");


    String returncode = (String) outcome.get("Re turnCode");
    String resulttext = (String) outcome.get("Re turnText");


    However entryset 2 is a bit tricky as it is a hashmap and it contains another hashmap..so it may contain multiple levels (e.g leavel0 , level1) and multiple items (another hasmap inside each level)
    So can't use String returncode =(String) anothermap.get( "Level");
    because i dont know the level name (e.g 1,2,3)...

    How can i get the contents of each level and contents of each item in that level??

    Thanks
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    If the maps are nested to an arbitrary depth, I would use recursion.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      I find all these simple values in those Maps a bit suspicious: can't you build a
      class for those attributes? It looks a bit Fortranesque to me now ...

      kind regards,

      Jos

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Originally posted by JosAH
        I find all these simple values in those Maps a bit suspicious: can't you build a
        class for those attributes? It looks a bit Fortranesque to me now ...

        kind regards,

        Jos
        I suspect that when switches to Java from a scripting language, everything still looks like a Map ;-)

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by BigDaddyLH
          I suspect that when switches to Java from a scripting language, everything still looks like a Map ;-)
          Ah, ok, capiche; now just lets hope that no "dynamic variables" such as var1, var2 ...
          come in again. ;-)

          kind regards,

          Jos

          Comment

          Working...