This question fought me in time. Why sometimes Android Studio wants me to use For Every and not For Loop, because when I use For Loop, I get a warning that I can use for everyone (and with Alt + Enter it offers me autofix).
For example, suppose this code
String a = ""; String[] array = {"A","B","C"}; for(int i = 0; i < array.length; i++) { a += array[i]; a += ","; }
I get a warning
and this fix offered by Android Studio
for (String anArray : array) { a += anArray; a += ","; }
Is he more perfect? Is there a reason why I should get a warning for actual use only for the loop?
Or when is it better for the cycle or for everyone?
java foreach android-studio for-loop
user1714647
source share