Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create multiple objects dynamically

 
Ananth Mahadevan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a class like this. Based on a certain value (which can change), I want to create objects. For eg.: if the value is 3, I want to create 3 objects for the below class. If the value is 10, I want to create 10 objects. The value is obtained from the first line of a file.

Please let me know how I can do this?



I want to get something like this, but dynamically:


Thanks,
Ananth.
 
Paul Clapham
Sheriff
Posts: 21136
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume your question is not actually how to create the objects, you seem to know how to do that. It appears you don't know where to put them once you have created them. Well, you should put your created objects into an array, or a List.
 
John Jai
Rancher
Posts: 1776
 
Ananth Mahadevan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will it be something like this?

Assuming value to be 5.
for (i = value; i > 0; i--) {
Inputs inputs = new Inputs();
}

But how can I get 5 distinct objects?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already answered:
Paul Clapham wrote:you should put your created objects into an array, or a List.
 
Ananth Mahadevan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok got it. Thank you for the quick response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic