Hallo Divi,
und folgender Code wirft bei Dir einen Fehler?
package spielwiese;
import java.util.ArrayList;
import java.util.List;
public class TestArrayList {
public class Auto {
String farbe="";
int kW=0;
Auto(String farbe, int kW) {
this.farbe=farbe;
this.kW=kW;
}
public String toString() {
return "Auto (" + farbe +") " + kW + "kW";
}
}
public static void main (String args[]) {
TestArrayList t = new TestArrayList();
List<Auto> autoListe = new ArrayList<Auto>();
Auto a1 = t.new Auto("rot", 55);
Auto a2 = t.new Auto("schwarz", 75);
Auto a3 = t.new Auto("gruen", 50);
autoListe.add(a1);
autoListe.add(a2);
autoListe.add(a3);
System.out.println(autoListe);
}
}
Mit freundlichem Gruß
Micha