I have made a part of my program that needs to match something out of an arrayList with Hashmap key.
When there is a match, I would like it to replace the key with the key from the ArrayList. (ArrayKey2)
So I made up the folowing:
Look if there is a similair key between key from multihashmap (mapFile1) and the ArrayKey2.
If yes, then get the value out of the mapFile1.
And put the ArrayKey2 with the values in the mapFile1 again.
But I don't understand why it won't get in the Hashmap.
With my MultiHashMap the keys are Strings, and the values Objects.
// Get the keys from mapFile1. Set<String> keySet = mapFile1.keySet(); Iterator<String> keyIterator = keySet.iterator(); // Go through the keys one by one. while (keyIterator.hasNext()) { // Put the key in an Object. (It can't become a String right away.) Object keyObj = keyIterator.next(); // Put key in String. String key = "" + keyObj; for (int i = 0; i < ArrayListFileData2.size(); i++) { // Get the data out of the arrayList and put it in a String. String ArrayKey2 = ArrayListFileData2.get(i);; // Look if they match. if (key.equalsIgnoreCase(ArrayKey2)) { //System.out.println("Loop key: " + key); //System.out.println("Loop ArrayKey2: " + ArrayKey2); System.out.println("Match: " + key + ArrayKey2); // Get the values from that certain key. Collection values = (Collection) mapFile1.get(key); Iterator valuesIterator = values.iterator(); while(valuesIterator.hasNext()) { Object ValueIT = "" + valuesIterator.next(); System.out.println(ValueIT); // //mapFile1.put(ArrayKey2, ValueIT); } } } }
If I activate this lime: mapFile1.put(ArrayKey2, ValueIT)
Then it says:
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(Unknown Source) at java.util.ArrayList$Itr.next(Unknown Source) at SecondMatcherGridLayout.Matcher(SecondMatcherGridLayout.java:436)
And this: at SecondMatcherGridLayout.Matcher(SecondMatcherGridL ayout.java:436) would be this line: Object ValueIT = "" + valuesIterator.next();
The code as it is shown above works.
But the problem is that when I activate mapFile1.put(ArrayKey2, ValueIT) I get the error.
And I realy have no clue about why....