处理对象时如何在java中使用地图 [英] How to use a map in java when dealing with objects
本文介绍了处理对象时如何在java中使用地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我正在创建一个程序,允许用户在保险单中指定他们想要的保险。作为其中的一部分,我需要使用地图来跟踪每个特定保险单的所有者。
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.
我已经看到了如何使用地图的例子至 String
和 int
值,但对于自制课程( InsurancePolicy
在我的情况下)。
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).
所以,我试图这样做,但我得到非法的表达式警告:
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.
推荐答案
对,这是无效的Java。尝试,
Right, that's invalid Java. Try,
Map<String, InsurancePolicy> coverOwnerMap = new HashMap<String, InsurancePolicy>();
这篇关于处理对象时如何在java中使用地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文