I have the following function that searches the entire list and when it finds the occurrence, it returns it at the end.
private static int getIndexRouteInListByRef(List<Route> mArray, String search) {
int outIndex = -1;
for (int i = 0; i < mArray.size(); i++) {
if (mArray.get(i).getRef().equals(search)) {
outIndex = i;
}
}
return outIndex;
}
How could it be optimized so that when it finds the occurrence, leave the loop and return the index?