• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to create multiple objects dynamically  RSS feed

 
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.
 
Sheriff
Posts: 23643
48
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.
 
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?
 
Author and ninkuma
Marshal
Posts: 66786
168
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!