使用 java 集合框架中的地图所需的建议
我试图了解 Java Collections Framework 中的 Map 是如何工作的。我知道它将值映射到键,但是如果我想创建一个具有名字、姓氏、性别的员工怎么办,和一个ID(我将用它作为密钥)。
所以我尝试了这段代码...
Map <Employee> employeeMap = new HashMap<String,String,String,String,int>();
但它不喜欢这样,因为它只需要输入两个参数。那么,如何将整个员工添加到包含两个以上值的 Map
中?
I am trying to understand how a Map
from the Java Collections Framework works. I understand that it maps values to a key, but what if I want to create an employee who has a first name, last name, gender, and an ID (which I would use as the key).
So I tried this code...
Map <Employee> employeeMap = new HashMap<String,String,String,String,int>();
But it doesn't like this, as it wants only two parameters to be entered. So, how do I add an entire employee to the Map
which contains more then two values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有一个 Employee 类,不是吗?
当你有一个 Employee 对象时,说“
em
”那么你可以
you have an Employee class, don't you?
when you have an object of Employee, say "
em
"then you can