HashMap with multiple values under the same key

前端 未结 22 2106
旧时难觅i
旧时难觅i 2020-11-22 06:49

Is it possible for us to implement a HashMap with one key and two values. Just as HashMap?

Please do help me, also by telling (if there is no way) any other way to

22条回答
  •  深忆病人
    2020-11-22 07:09

    I could not post a reply on Paul's comment so I am creating new comment for Vidhya here:

    Wrapper will be a SuperClass for the two classes which we want to store as a value.

    and inside wrapper class, we can put the associations as the instance variable objects for the two class objects.

    e.g.

    class MyWrapper {
    
     Class1 class1obj = new Class1();
     Class2 class2obj = new Class2();
    ...
    }
    

    and in HashMap we can put in this way,

    Map 
    

    WrapperObj will have class variables: class1Obj, class2Obj

提交回复
热议问题