I have an ArrayList of say, this object:
class Object() {
String name;
double price;
int id;
}
I want to find the index of the ArrayList that contains the element where the name field is equal to a given string. For example:
public int findIndex(ArrayList<Object> list, String name) {
for(Object o : list) {
if (o.getName().equals(name) {
//return index
}
}
}
What's a good way to return the index?