[SOLVED] A better way to do this - ArrayLists
Quote:
public java.util.List<com.netcb.sas.adapters.gms.Town> getTowns() {
ArrayList<Town> towns = new ArrayList<Town>();
Town town = new Town();
try{
java.util.Iterator locations = new DBUtil().getTowns().iterator();
while(locations.hasNext()){
Location loc = (Location)locations.next();
town.setId(loc.getNoLocation());
town.setName(loc.getDescLocation());
towns.add(town);
}
return towns;
}
catch(HibernateException he){
he.printStackTrace();
}
catch(Exception e){
e.printStackTrace();
}
//todo
return null;
Town and Location are my own defined classes but not related. Is there a way to achieve the same results without a loop or without Quote:
town.setId(loc.getNoLocation());
town.setName(loc.getDescLocation());
Is there a better way to do this?