-3

So let's say I have a class named Car, and I have multiple Car objects, (c1, c2, c3...c1000) How do I assign them in a list automatically. I have an idea like

public List<Car> getCarList() {
    List<Car> list = null;

    String temp = "c";

    for (int i = 1; //starts at car1
            i < 1001; //ends at car1000
            i++) {
        temp += i;
        list.add(temp); //here's the part where I don't know what the exact input should be
        temp = "c";
    }

    return list;
}

If there's some flaws in this idea or it's straight up wrong please suggest another way to do this.

0 Answers0