English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

In java, is there anyway to instanciate an object and name it a word stored in a String variable? like if i had:

String thing=test;
random test=new random();
thing=something

would there be anyway to create another instance of class random without having to maually type it in? in otherwords, is there any way to name the object using the string's name (thing) and not the actual value stored in it. Basically i want it to say something like this:

String thing=everything;
random thing=new random();

but to have the object named everything, not thing. Can anyone help me?

2006-11-19 13:52:35 · 3 answers · asked by random_guy7531 4 in Computers & Internet Programming & Design

3 answers

I dont think so. sorry

2006-11-19 14:00:56 · answer #1 · answered by Cannibal Ox 4 · 0 1

I guess you would want to use a Hashtable to store objects based on a string key.

There's a example on this page: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Hashtable.html

2006-11-19 15:10:45 · answer #2 · answered by Ben 2 · 1 0

you can use java.util.map

I guess hashtable would be best implementation for you case.

2006-11-21 13:08:52 · answer #3 · answered by srihari_reddy_s 6 · 0 0

fedest.com, questions and answers