Fix that Java: The Broken Basket


Nice basket. We would like to put Jonathan apples only in that. But something is fishy here…

class Main {
    public static void main(String[] args) {
        Basket basket = new Basket();
        basket.add("Jonathan");
    
        // ... 
    }
}
import java.util.List;
import java.util.ArrayList;

class Basket {
    private List<String> apples = new ArrayList<>();

    public void add(String apple) {
        if (apple.equals("Jonathan")) {
            apples.add(apple);
        }
    }

    @Override
    public String toString() {
        return apples.size() + " piece(s) of Jonathan.";
    }
}

Fix that Java code!

When you fixed that then: fix it again but this time you are not allowed to add any characters to the code.