This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Hi, I am pretty new to this wonderland of Java.Well,my questions is as follows: Assume that i have defined a String variable: String myString = "abcd"; Now my goal is to create an arraylist with the same name as that of the value assigned to myString.That is the goal is to achieve: ArrayList abcd = new ArrayList(); However,when i perform the following i get an error: ArrayList :myString = new ArrayList(); ERROR is -incompatible types found : java.util.ArrayList required: java.lang.String
Can you help me to resolve this issue? Thanx, Ritu
"If I would have known what I was doing,then I wouldn't have termed it as research!!".
Jyoti: Is it safe to assume that you are coming to Java from Perl? What you are asking to do is something that is very much along the Perl vein. In Java, variables are strongly typed. As far as I know, there is nothing in Java that is directly analogous to this feature of Perl. You cannot use the value of one variable as the variable name of another. What you can do is something like the following:
Note that there is nothing like:
(It's been quite a while since I've done Perl, and I never did it heavily to begin with; the actual syntax may be slightly different) Hope that this helps.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joined: Mar 22, 2003
Hi Joel, Thanks a lot for your help..i really appreciate it..well, even i guess i tried to mess perl and java.. Regards, Jyoti.