How do I create a certain amount of instances at runtime?

If i want a certain amount of instances at runtime, how can i do it?

say, if i write a program that read an input from a keyboard and create a certain amount of instances. or read an input from a keyboard to be an instance variable.Can i do it? How? Please help!

[276 byte] By [Spongeboya] at [2007-11-27 11:18:07]
# 1

please elaborate your question

student-javaa at 2007-7-29 14:29:02 > top of Java-index,Java Essentials,New To Java...
# 2

> If i want a certain amount of instances at runtime,

> how can i do it?

>

> say, if i write a program that read an input from a

> keyboard and create a certain amount of instances.

> or read an input from a keyboard to be an instance

> variable.Can i do it? How? Please help!

How much instance do you want? 1 gm? 10 gms? 1 pound? a kilo?

petes1234a at 2007-7-29 14:29:02 > top of Java-index,Java Essentials,New To Java...
# 3

> If i want a certain amount of instances at runtime,

> how can i do it?

int numInstances = getNumInstancesFromSomewhere();

List<Foo> fooList = new ArrayList<Foo>(numInstances);

for (int ix = 0; ix < numInstances; ix++) {

fooList.add(new Foo());

}

jverda at 2007-7-29 14:29:02 > top of Java-index,Java Essentials,New To Java...
# 4

> please elaborate your question

Yes, please do.

jverda at 2007-7-29 14:29:02 > top of Java-index,Java Essentials,New To Java...