0

So I want to draw multiple things so I am writing a method that accepts strings.

I'm not really sure how to do this or if this is even legal. Also if there is a better way of doing this please let me know. I have to draw more than 10000 cubes so I don't really want to type it our that much times.

So here's what I am thinking,

I have a method that draws thing that takes in a string.

public void drawCube(String s)
{
  Box s = new Box(10, 10, 10);
}

and then have some kind of for loop that calls this method every time, concatenating the i into some name for how much I need to call this.

I know that this is wrong since s is already used. How would I use the stored string of s for the name instead of s itself?

Is this possible or not?

And is there a better way of doing this?

  • Short answer: No. Use something like: Map or Box[]. – Kylar Sep 23 '16 at 22:25
  • 2
    You might think you need this, but, with what you've shown, you really don't. Regardless, [here's](http://stackoverflow.com/questions/6729605/assigning-variables-with-dynamic-names-in-java) how you would do something similar. That's a duplicate by the way, if anyone has votes left. – Sotirios Delimanolis Sep 23 '16 at 22:33

0 Answers0