I'm developing a system where the user types a wrong word, and I changed one or another letter of that word to correct, just for the same study purposes, and I have to go through the whole String and take an example, the user type Caiaaaque and I have to go through this letter-by-letter string and replace the error with the correct getting kayak.
The code snippet looks like this:
public String retornaPalavra(String palavra){
//for pra percorrer a String
for(int i; i<palavra.lenght()-1;i++){
if(palavra.charAt(i)==palavra.charAt(i+1)){
palavra = palavra.replaceFirst(palavra.charAt(i), '');
i = i-1;
}
}
retorno = palavra;
}
Now the problem is that if the user types Caiaaaque for example he removes all the 'a' getting thus Cique. And I want to return to Kayak.