Results 1 to 2 of 2
  1. #1
    deshmukhmp is offline Member
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Default Regarding map ina java

    I have to get the frequency count of each integer in a numeric string further to remove least occured element based on the support value provided as a parameter to the following function from the map

    the following is the code

    public void discardentry(int support)
    {
    Iterator it = m.entrySet().iterator();
    while (it.hasNext()) {
    Map.Entry pairs = (Map.Entry)it.next();
    if(Integer.parseInt((pairs.getValue()).toString()) <support)
    m.remove(pairs.getKey());
    //System.out.println(pairs.getValue());

    }
    }

    I'm receiving the exception named concurrent modification.
    let me know the code for given a map to compare given value with a map value and to remove the entries from the map which are having less value than a given value

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,999
    Blog Entries
    7
    Rep Power
    19

    Default Re: Regarding map ina java

    You are trying to remove an entry from your map 'behind the back' of the iterator, hence the Exception. A map keeps a 'modifiation counter' and increments it each time the map is modified. When an Iterator is instantiated it registers this modification count. Each time an Iterator has to do something it compares the map's modification counter and its own version; when they differ the map was modified 'behind the back' of the Iterator and it throws an Exception. Read the API for the Iterator interface: an Iterator can (optionally) remove an entry from the Collection it iterates over ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •