I’m trying to call a method from another method in the same class to check if something entered by the user is in an arrayList. If it is in the arrayList, I want to add 1 to its quantity. If it’s not in the arrayList, I’ll add it to the arrayList. Here’s what I have:
public Item searchForItem(String n){
for(int i = 0; i < s.size(); i++){
Item y = s.get(i);
if(y.getName().equals(name)){
return y;
}
}
return null;
}
public void addItem(Item f) {
s.add(f);
}
I know that I’ll need an if statement in the addItem method, but I’m not sure how to write it.
Is there a way to check if either y was returned or whether null was returned?
Just call the searchForItem method passing name as an argument.