Java many to many association map

前端 未结 7 1059
难免孤独
难免孤独 2020-12-16 01:29

I have two classes, ClassA and ClassB, as well as a \"many to many\" AssociationClass. I want a structure that holds the associations

7条回答
  •  孤城傲影
    2020-12-16 01:34

    rmarimon is right that it requires two maps, but I think you want A-B, not A-data and B-data.

    So you just simply need two maps:

    
        Hashmap bByA = new HashMap();
        Hashmap aByB = new HashMap();
    

    This gives you everything you seem to want, free and easy.

提交回复
热议问题