How do I dynamically name objects in Java?
Posted
by hatboysam
on Stack Overflow
See other posts from Stack Overflow
or by hatboysam
Published on 2010-04-26T03:54:13Z
Indexed on
2010/04/26
4:03 UTC
Read the original article
Hit count: 298
Let's say I needed to make a series of String[] objects.
I know that if i wanted to make a string array called "test" to hold 3 Strings I could do
String[] test = new String[3];
But let's say I needed to make a series of these arrays and I wanted them to be named, 1,2, 3, 4, 5... etc. For however many I needed and I didn't know how many I'd need.
How do I achieve a similar effect to this:
for (int k=0; k=5; k++){
String[] k = new String[3];
}
Which would created 5 string arrays named 1 through 5. Basically I want to be able to create array objects with a name detemined by some other function. Why can't I seem to do this? Am I just being stupid?
© Stack Overflow or respective owner