Hope you don't mind I'm asking a newbie question about the use of iterator for a arrayList / List.
I have a Building Class with a few data members:
public Building() {
private String buildingName;
private String buildingType;
private double width;
private double length;
private String managerName;
....
}
I've already set toString() as follow to access the name String and I'm NOT allowed to change toString to return a different data member.
public String toString() {
return buildingName;
}
I've created a bunch of building objects in the Building class by loading a building.xml file, and I've used iterator to create an array/list of buildingNames to be viewed in a swing ComboBox (but let's ignore those swing component below and focus on the just the logics):
// Create building combo box model.
buildingComboBoxModel = new DefaultComboBoxModel<Building>();
buildingsCache = new ArrayList<Building>(buildings);
Iterator<Building> i = buildingsCache.iterator();
while (i.hasNext()) buildingComboBoxModel.addElement(i.next());
// Create building list.
buildingComboBox = new JComboBoxMW<Building>(buildingComboBoxModel);
buildingComboBox.addActionListener(this);
buildingComboBox.setMaximumRowCount(10);
buildingSelectPanel.add(buildingComboBox);
How many ways do can you think of and how in putting together an list of buildingType using iterator without significant code changes?
If I need to modify some of the buildingType Strings in some situations by adding a String to it,
say in one building,
String buildingName = "Adam's Place";
String buildingType = "Greenhouse";
[post edit]
e.g. I need to change buildingType to "Greenhouse Type 1" for "Adam's Place" and change another building's buildingType to "Greenhouse Type 2"
Can it be done using iterator and how?
If not, other ways are welcome
Thanks in advance!