I'm a Student, so I'm not an expert. I'm trying to do the following:
I have an HashMap with some Keys (String) and Values (String[]). I also have a file.txt with all the synonyms. I was trying to add the synonyms to my HashMaps, and to get the values of the existing Key (synonym of the synonyms).
Here is my HashMap:
HashMap<String, String[]> qA = new HashMap<String, String[]>();
Here is my code:
for (Map.Entry<String, String[]> entry : getqA().entrySet()) {
for (String synonym : getSynonym(entry.getKey()))
addWord(synonym.toLowerCase(), entry.getValue());
}
The method getqA returns the HashMap. The method addWord is practically the same as nameOfTheHashMap.put();
There is the method getSynonym(String word):
public String[] getSynonym(String word) {
for (String[] list : abc)
for (String wordIntoList : list)
if (wordIntoList.toLowerCase().equals(word.toLowerCase().replace(" ", "")))
return list;
return new String[] {};
}
"abc" is an ArrayList<String[]>
(contains file.txt) which contain on every index a line. A line is formed by sinonyms with the same meaning.
How do I fix the error ConcurrentModificationException? As I said, I'm not an expert, it's the first year I study Java. I've tried to look other topics, but I wasn't able to fix the problem.
Thanks in advance!
As requested, my addWord method:
public static void addWord(String key, String[] values) {
qA.put(key, values);
}