I need to change my for loop to foreach loop in this method, how can i do that? ( Can add full class, if necessary)
public String decode(String input) {
String[] letters = input.split(" ");
StringBuilder ret = new StringBuilder();
for(int i=0; i<letters.length; i++)
ret.append(decodeMap.get(letters[i]));
return ret.toString();
}
You should specify which language you are using. I'm assuming java. Use for(datatype var : collection)
.
Here is what it would look like
public String decode(String input) {
String[] letters = input.split(" ");
StringBuilder ret = new StringBuilder();
for(String s : letters){
ret.append(decodeMap.get(s));
}
return ret.toString();
}