【发布时间】:2017-01-15 23:20:51
【问题描述】:
我想从 multiMap 中打印对象的所有键和所有属性。 同一个键可以有不同的对象。
我使用以下代码创建了 multiMap:
Multimap<Integer,Country> country=ArrayListMultimap.create();
我的班级国家是:
class Country {
String country;
int population;
}
如何从中检索所有对象属性: 使用 HashMap 我正在使用以下代码:
for (Map.Entry p : country.entrySet()) {
Country country=(Country)p.getValue();
nameCountry=country.country;
population=country.population;
}
【问题讨论】: