I'm learning lambdas and I have an exercise to rewrite the while loop in this code using lambdas. This method gets encoded user input and returns decoded. I faced this problem and can't understand what I'm supposed to do. (I know that it's not hard, but I just can't get the concept.) I didn't find any similar questions here.
p.s. Also, one more qustion - can this while loop( or maybe whole method) be reworked with method reference?
public String decode(String input) {
StringBuilder letters = new StringBuilder();
input = input.toUpperCase();
int i = 0, j = 0;
while (i < input.length()) {
char symbol = input.charAt(i);
char keySymbol = KEY.charAt(j);
int newIndex = (ALPHABET.indexOf(symbol) - ALPHABET.indexOf(keySymbol)) % ALPHABET.length();
char newSymbol = ALPHABET.charAt(newIndex);
letters.append(newSymbol);
j = ++j % KEY.length();
i++;
}
return letters.toString().toLowerCase();
}
forEeachIndexed(()->{})?