I have the following class as a example to a similar problem im having ...
Class Car
code:
public class Car {
private String name;
public Car(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
Class CreateCarFromList
code:
public class CreateCarFromList {
private List carNames = new ArrayList();
private List carObject = new ArrayList();
/** Creates a new instance of CreateCarFromList */
public CreateCarFromList() {
carNames.add("Red");
carNames.add("Blue");
carNames.add("Yellow");
Iterator it = carNames.iterator();
while (it.hasNext()) {
Car x = new Car((String) it.next());
carObject.add(x);
}
}
}
in the last class i have an arraylist,carNames, with the following value
["Red", "Blue", "Yellow"]
than i do an iteration and create an instance of an object in each iteration and add it to another arraylist, carObject
my problem is what do i need to do, to add to the Car class or perhaps to CreateCarFromList Class.
so that i can say for a
String s = "Red";
give me from carObject list the Car object that has that attribute. (hope this make sense)
--------------------
FD