Here is my part of code, which throws exception:
List<Car> car1store = new ArrayList<>();
//adding any number of cars to car1store
Random rnd = new Random();
double randNumber = rnd.nextDouble();
if (randNumber < 0.25) {
int attempt = rnd.nextInt(car1store.size());
Car car = car1store.get(attempt);
}
I have already searched for why does this exception appear, but I seriously can't find how car1store.size() can be a negative number. The least number it can be is only a zero. Can you see my mistake?