This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Naming an array with an existing string variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Naming an array with an existing string variable" Watch "Naming an array with an existing string variable" New topic
Author

Naming an array with an existing string variable

Jake Cirino
Greenhorn

Joined: Jul 27, 2012
Posts: 17

Hey guys, I'm making a ASCII character 'game engine' persay.

I want flexibility for other programmers and ease of making and generating new areas.

So I have a function with 5 params; the character you want to generate, the width and height of the generation, a boolean which determines if you want an array with data of the characters and their positions, and the name of the array.

The problem is, I don't know how to actually take the name that they input into the code and turn it into the array's name.

Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

I am not sure the need to have a variable name dynamically. What is the purpose of doing so. If you have something to do with the name given as input and the array, why can you not go for Map. This seems to be weird solution, hoping to get something better.


Ashwin Sridhar
SCJP | SCWCD | OCA
Jake Cirino
Greenhorn

Joined: Jul 27, 2012
Posts: 17

Ashwin Sridhar wrote:I am not sure the need to have a variable name dynamically. What is the purpose of doing so. If you have something to do with the name given as input and the array, why can you not go for Map. This seems to be weird solution, hoping to get something better.

I'm trying to make an ASCII game engine so that other developers can easily render multiple things and be able to keep track of them in an array.

It's just for flexibility and ease of use within the program.
Ashwin Sridhar
Ranch Hand

Joined: Jul 09, 2011
Posts: 272

It's just for flexibility and ease of use within the program


Not sure if this would contribute to the purpose. You could very well have a more meaningful name, say gameEngineArray or something which makes more sense.

One more thing which I would suggest is, instead of using



you could use



This good be a good coding practice.
Jake Cirino
Greenhorn

Joined: Jul 27, 2012
Posts: 17

Ashwin Sridhar wrote:
It's just for flexibility and ease of use within the program


Not sure if this would contribute to the purpose. You could very well have a more meaningful name, say gameEngineArray or something which makes more sense.

One more thing which I would suggest is, instead of using



you could use



This good be a good coding practice.

So basically, what I'm wanting to do is impossible in java?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60774
    
  65

So would following established naming conventions.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jake Cirino
Greenhorn

Joined: Jul 27, 2012
Posts: 17

Bear Bibeault wrote:So would following established naming conventions.

Alright thank you guys.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
That is a very peculiar design you are trying to achieve. The only thing I can think of is that you create a Map<String, Foo[]> and you can put names in as the keys and the arrays as the values. You cannot change the names of variables unless you create a program which emits the code and compiles it later.
As well as naming conventions, please avoid such long lines and use spaces, not tabs, for indentation.
Also avoid == true and == false like the plague, as already suggested.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Naming an array with an existing string variable
 
Similar Threads
Sun Cirtification
AOOB exception in my CODE-PLEASE HELP!
Have board printed twice in second method. Board class.
Error handling problem
Confused about setting PATHS in Windows 7