4
When we created the for traditional we do this way:
for(int i = 0; i<strs.lenght; i++){
Log.wtf(TAG, "Jon Snow is "+strs[i]);
}
Now I have this foreach:
for(String str: strs){
Log.wtf(TAG, "Jon Snow is "+str);
}
In some cases, we need index. As to the for traditional, all right, it is already stated in itself. And if it is in the foreach? Can you catch the index of the list within the foreach in Java? If I declare a int i outside it, and increasing within it is a legal practice if it is not possible to recover the index, or it is better to create a for traditional?
You could do this using the index method if you use a List, but with an array I don’t think you can
– Denis Rudnei de Souza
@Denisrudneidesouza this has performance problems (
o(n)for disordered lists), plus problems with possible repetitions (if I have 5 times the same element, I believe thatindexOfreturn to first valid position).– Jefferson Quesado