HashMapの使い方法

HashMap<String, Integer> rotoHashMap = new HashMap<String, Integer>();
String xxKey = "";
// HashMapの構築
for (int i = 0; i< xxxList.size(); i++) {
    xxKey =  xxxList.get(i).getName();
    if (rotoHashMap.containsKey(xxKey)) {
        rotoHashMap.put(xxKey, rotoWakeGokeiHashMap.get(xxKey) + 1);
    } else {
        rotoHashMap.put(xxKey, 1);
    }
}

List<xxxxxInfo_st> xxxLt = new ArrayList<xxxxxInfo_st>();
// 上記構築されたHashMapに従って、処理を行う
// eg. 重複的なnameではないレコードを削除する
for (int i = 0; i< xxxList.size(); i++) {
    xxKey = xxxList.get(i).getName();
    if (rotoHashMap.containsKey(xxKey) && rotoWakeGokeiHashMap.get(xxKey) > 1) {
        xxxLt.add(xxxList.get(i));
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章