When we create the traditional for
we do it like this:
for(int i = 0; i<strs.lenght; i++){
Log.wtf(TAG, "Jon Snow is "+strs[i]);
}
Now I have the following for
each :
for(String str: strs){
Log.wtf(TAG, "Jon Snow is "+str);
}
In some cases, we require index
. As for traditional for
, that's fine, it's already declared in itself. What if it is in for
each ? Can you get the index from the list within for
each in Java? If I declare a int i
off of it, and increment in is legal practice if it is not possible to retrieve index , or is it better to create a for
traditional?