I'd like to write a program which creates a set of objects in a loop....
(i.e.)
String newFirm = "empty";
for(int i=0; i<30; i++)
{
newFirm = "firm" + i;
firm newFirm = new firm();
}
and then of course I would need something like
stringToObject = "firm" + x;
stringToObject.type = "service";
stringToObject.size = 10000;
Obviously this code is fictional, but It expresses how I'd ideally create and call for objects. The nature of this program is such that the final number of firms (or other objects) are not known at the time of compiling.
Is there a method by which I can convert a given string into the name of an object (either to call or to create) as well as creating objects "on the fly"?
Sounds like a job for an ArrayList.
ArrayList<Firm> myList = new ArrayList<Firm>();
And in your loop,
Firm firm = new Firm();
firm.type = "service";
myList.add(firm);
And to get it,
Firm f = myList.get(index);