I'm creating a simple spellchecking program. It basically loads in a dictionary and misspelled words. I have a function aimed at removing repeats, and another function that generates all vowel combinations of a word to be checked.
I'm having an issue with my vowel function. I keep getting CurrentModifcationException, but I feel like it should be able to modify the array its adding words to as the array is statically defined at the top.
Basically this function takes in an ArrayList and recursively adds additional words to the ArrayList which are vowel combinations of the word inputted. An example is if 'who' was inputted, it would add 'wha, whi, whe, whu' to the array list.
The Code
DEFINED AT TOP OF CONTAINER CLASS
private static List<String> vowelList = new ArrayList<>();
private static ArrayList<String> checkList = new ArrayList<>();
private static void feedWordsForVowelCheck() {
for(String temp : checkList) {
System.out.println("Checking vowels for: " + temp);
// createVowelCombosStatic(temp, 0);
createVowelCombos(temp, 0 , checkList);
}
// System.out.println("Does this finish?");
}
private static void createVowelCombos(String word, int start, ArrayList<String> checkList) {
StringBuilder sbAddWord = new StringBuilder(word);
String[] splitWord = word.split("");
if (start==splitWord.length) {
checkList.add(word);
return;
}
if (splitWord[start].matches(".*[aeiou]")) {
for (int j = 0; j < 5; j++) {
sbAddWord.setCharAt(start, vowelList.get(j).charAt(0));
createVowelCombos(sbAddWord.toString(),start+1, checkList);
//System.out.println(sbAddWord.toString());
}
}
else
createVowelCombos(sbAddWord.toString(),start+1, checkList);
}