要進行的操作是,遍歷map.判斷key值是否存在。如果存在,,則this key對應的valuez增加一個list,否則的話,就重新再添加一組鍵值對,
private Map> modleLists() {
List lists = new ArrayList();
Map> maps = null;
for (int i = 0; i < carInfoLists.size(); i++) {
if (maps == null) {
maps = new HashMap>();
lists.add((carInfoLists.get(i)));
maps.put(carInfoLists.get(i).getModleName(), lists);
} else {
Iterator>> it = maps.entrySet().iterator();
while (it.hasNext()) {
Entry> next = it.next();
String key = next.getKey();
if (carInfoLists.get(i).getModleName().equals(key)) {
CarModle carModle = carInfoLists.get(i);
maps.get(key).add(carModle);
} else {
lists.clear();
lists.add(carInfoLists.get(i));
maps.put(carInfoLists.get(i).getModleName(), lists);
}
}
謝謝給位,自己已解決