Build Variable Name Dynamically

Joined
Nov 20, 2006
Messages
1
Reaction score
0
Hello All,

I'm new to Java programming and I have this issue. I have a requirement to search a table for a field name, retrieve the value and then build a HashMap based on that value retrieved from the table...:? Here is the code I think will handle this...
if (results != null) {
String ntwktype = results.getString("NETWORKTYPE");
String newLocations = "the" + ntwktype + "Locations";
System.out.println("Location Name: " + newLocations);
HashMap newLocations = new HashMap();
theLocations.put(ntwktype, newLocations);
populateOneRow(results);
return getInfo(ntwktype,locationId);
}


My issue: The line in bold, newLocations is a String, so naturally i'm getting an error because of the data type conflicts. I want the value of the String as the HashMap name. So, if newLocations = "Kentucy" I want the next line to be
HashMap Kentucky = new HashMap();

I know in UNIX the $ gets you the value of the variable so I'm looking for something like this that works with Strings in JAVA.

Thanks for your help :veryprou:
Ozarka
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top