5
I have a list of customers and on a certain screen the user can do a search and edit the clients of the list that is quite extensive, comparing these two examples which would be the best to work?
Example 1:
for (int i = 0, tamI = listAll.size(); i< tamI;i++)
if (listAll.get(i).getNome().toLowerCase().startsWith(query.toLowerCase()))
listResult.add(listAll.get(i));
Example 2:
for (Cliente item : listAll)
if(item.getNome().toLowerCase().startsWith(query.toLowerCase()))
listResult.add(item);
Related : https://answall.com/questions/63005/qual-possuí-um-performant-bestfor-ou-foreachrange
– viana
There is difference between reporting the size in the loop condition or outside of it?
– rray
This site is great for comparing Javascript/Jquery methods : https://jsperf.com/
– Bruno
@Bruno but no Javascript/Jquery code here!
– viana
I am using the second example, because it is an implementation of the language I believe it is optimized for these situations
– GabrielLocalhost
@Gabriellocalhost Did the answer resolve what was in doubt? Do you need something else to be improved? Do you think it is possible to accept it now?
– Maniero