I want to know how to iterate through the following Arraylist.
public class FruitHandler {
private ArrayList<Fruits> fruit;
private ArrayList<Integer> fruitUID= new ArrayList<>();
public static FruitHandler getInstance() {
return instance;
}
public void addFruit(Fruit fruit) {
this.fruitUID.add(fruit.getfruitUID());
this.fruit.add(fruit);
}
}
What I want to do is to iterate through the fruitUID and return the instance of that fruit class that is stored in ArrayList<Fruits> fruit which matches my given UID.
Example, I have an fruitUID = 10, I want to have the reference of the instance of the fruit class that is stored in ArrayList<Fruits> fruit which have its fruitUID = 10.