Reputation: 385
I'm working on an Android project and I have a problem with creating objects dynamically.
For example, I want the events named like this:
*event1
*event2
...
I'm used to work in PHP, and I know I can't do this the same way in Java because the code has to be compiled before the program starts.
I don't know how many objects the program will have to make, as the data comes from an online database. I'm able to create 1 event if I put something like this:
Event event = new Event();
I would really like something to make an object for each event and store each object in a db4o database.
As I said, it's possible that there is only one event, but it is also possible that there are 100 events.
Upvotes: 0
Views: 193
Reputation: 405765
It sounds like you need a collection of events. Try putting them in a simple data structure like an ArrayList
(similar to an array, but it can expand in size at run time). This way you won't have multiple variables event1
, event2
, etc., but just one variable named events
(or something similar) that holds as many objects as you need.
Upvotes: 7