0

I'm going to manage received message from server in my android client. For this goal I'm using ArrayList(HashMap<String, Integer>) to store arrived messages.

private ArrayList<HashMap<String, Integer>> Notifications = new ArrayList<>();

Each message has a type and I store that in hash map as a key and put qty of that type of message as integer in HashMAp too as value.

Now I got CME when I'm trying to iterate over ArrayList to find and update or add new type of arrived messages.

I think, I did it in a right way, where is my fault:

    for(HashMap<String, Integer> pack : Notifications) {

        // Searching for Notification Type - If exist update the value
        for(Entry<String, Integer> item : pack.entrySet()){

            String key  = item.getKey();
            if(key.equals(type)){
                Log.e("We find the key here:", key);
                item.setValue(item.getValue()+1);
                found   = true;
                break;
            }
        }

        if(!found){
            ........
        }
    }
mehrdad khosravi
  • 2,228
  • 9
  • 29
  • 34
MAY3AM
  • 1,182
  • 3
  • 17
  • 42
  • 1
    Probably Using ConcurrentHashMap should address the problem – Saikat Biswas Nov 06 '15 at 11:22
  • Returns a Set view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's own remove operation, or through the setValue operation on a map entry returned by the iterator) the results of the iteration are undefined. – Saikat Biswas Nov 06 '15 at 11:26

0 Answers0