Any implementation of Map, i.e. two keys?

前端 未结 3 1736
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 06:58

I need a map that has two keys, e.g.

Map2 _employees;

So that I can

_empl         


        
3条回答
  •  暖寄归人
    2020-12-10 07:18

    My first thought was: the easiest way to do this, I think, would be two maps.

    Map< String, Map< String,Employee> > _employees;
    

    But from what it looks like, you just want to be able to look up an employee by either SSN or ID. What's to stop you then from making two maps, or at worst a class that contains two maps?

    As a clarification, are you looking for a compound key being employees are uniquely identified by the combination of their SSN and ID, but not either one by itself, or are you looking for two different ways of referencing an employee?

提交回复
热议问题