简体   繁体   English

java中处理对象时如何使用map

[英]How to use a map in java when dealing with objects

So, I'm creating a program that allows users to specify the insurance cover they want as part of an insurance policy.所以,我正在创建一个程序,允许用户指定他们想要的保险范围作为保险单的一部分。 As part of it, I need to use a map in order to track the owner of each specific insurance policy.作为其中的一部分,我需要使用地图来跟踪每个特定保险单的所有者。

I have seen examples of how to use a map with regards to String and int values, but nothing for self made classes ( InsurancePolicy in my case).我已经看到了如何使用关于Stringint值的映射的例子,但对于自制类(在我的例子中是InsurancePolicy )没有。

So, I'm trying to do it like this, but I get the illegal expression warnings:所以,我正在尝试这样做,但我收到了非法表达警告:

Map<String, InsurancePolicy> coverOwnerMap<String, InsurancePolicy>();

Any help would be very appreciated.任何帮助将不胜感激。

Right, that's invalid Java.是的,那是无效的 Java。 Try,尝试,

Map<String, InsurancePolicy> coverOwnerMap = new HashMap<String, InsurancePolicy>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM