【发布时间】:2013-03-08 06:12:16
【问题描述】:
如何从数组列表中过滤唯一对象。
List<LabelValue> uniqueCityListBasedState = new ArrayList<LabelValue>();
for (LabelValue city : cityListBasedState) {
if (!uniqueCityListBasedState.contains(city)) {
uniqueCityListBasedState.add(city);
}
}
这是我的代码。但问题是我需要过滤的不是对象,而是该对象内的属性值。在这种情况下,我需要排除具有该名称的对象。
那是city.getName()
【问题讨论】:
-
如果可能,考虑使用 HashMap。
-
这里的问题不是数据结构,imo