• 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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: 24082
54
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?
 
Marshal
Posts: 67225
169
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.
 
A feeble attempt to tell you about our stuff that makes us money
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!