I Just want to ask I am not sure, can "Java Reflection" help him? :roll:
Prateek<br />SCJP 1.5
posted 12 years ago
Yes, reflection could be used, but it would be a very obscure and complicated solution. This being the beginner forum, we should not get into that, but rather talk about how to use Java objects to solve the problem.
I am of course assuming that the actual problem is not "how to access variables called mac1, mac2, ..." but rather "how to store a varying a number of variables under the name mac".
I don't understand why you want to change the name of the variable in the code based on user input.
The variable name is used by the PROGRAMMER to keep track of stuff - the user should have no idea what's happening inside. Why should the user care if I name my variable Age, howOld, yearsSinceBorn, or q7dkjf3443?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I didn't say it. I'm just telling you what this tiny ad said.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop