File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Run-time reference naming Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Run-time reference naming" Watch "Run-time reference naming" New topic

Run-time reference naming

Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Class obj1 = new Class()
In above statement obj1 is object reference. If number of such object references needed at run-time is not known at compile time, how would you come up with next object reference e.g. obj2? In other words, can you put a function call in place of obj1 that return new name. I know you can use arrays but they are also fixed length. I have little knowledge that there are some container that adjust their size at run-type. Any other idea?
Barkat Mardhani
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Check out the Vector and the ArrayList classes. They are both resizable collections. so you could generate a number of object references at run time with out knowing in advance how many you were going to need. Of course, in many cases, you can do this with an array too, you just dont declare the array until you know how big it is going to be.

I agree. Here's the link:
subject: Run-time reference naming
It's not a secret anymore!