Given your description of "trying to find the most number of consonants in a row for a specific word in an array", I would think something along these lines (not compiled or tested - just to show the approach) would be a lot simpler to follow/debug/test/maintain (also only looks at the current word[i]
- an outer loop to iterate over your words is still needed:
String consgroups[] = word[i].split("[aeiou]"); // split on all vowels
int maxlen = consgroups[0].length, maxidx = 0;
for (int j = ; j < consgroups.length; ++j) // iterate over groups and find max
if (consgroups[j].length > maxlen)
{ maxidx = j;
maxlen = consgroups[i].length;
}
Given your comment about pig latin, I'm not sure why consonant groups other than at the beginning of the word are important, but perhaps I'm misunderstanding your description...
Edit: Now that I've looked a little harder, I think this approach might be more useful:
String vowels = "aeiou";
int i = 0;
while ((i < word.length) && (!vowels.contains(word.subSequence(i, i + 1))))
++i;
// now word[i] is the first non-vowel character in word
if (i == word.length) // word was all consonants
{ ...
}
else
if (i) // word has a consonant prefix
{ ...
}
else // word starts with a vowel
{ ...
}