Results 1 to 4 of 4
- 09-29-2008, 07:07 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 1
- Rep Power
- 0
Naming a class instance with a variable
Hi, I'm new to Java and have been trying to do something that I'm not sure is possible. I want to set the name of a class instance as the value of a char or String, like this.
for (int i = 0; i < 30; i++) {
char c = allButtons.charAt(i);
Button c = new Button();
}
With Button being a class and allButtons being a String. I don't want the name of the instance to be "c" I want it to be the value of c. Is this possible?
- 09-29-2008, 07:24 PM #2
You can't. Why do you think you need this?
Explain what you hope to accomplish and someone will be able to guide you how to do it the right way.
db
-
You don't want to do this as the name of the variable is meaningless here. It's the reference that really matters. What you want is likely an array or a hashmap, simple as that.
- 09-30-2008, 07:27 PM #4
Senior Member
- Join Date
- Sep 2008
- Posts
- 135
- Rep Power
- 0
Similar Threads
-
Which class and variable to choose?
By kian_hong2000 in forum New To JavaReplies: 8Last Post: 08-27-2008, 08:06 AM -
Instance Variable In Servlet
By javarishi in forum Java ServletReplies: 3Last Post: 06-14-2008, 09:28 AM -
Naming a Class
By Java Tip in forum Java TipReplies: 0Last Post: 12-22-2007, 12:21 PM -
Public class variable
By Java Tip in forum Java TipReplies: 0Last Post: 12-03-2007, 10:58 AM -
Instance variable
By Jack in forum New To JavaReplies: 2Last Post: 07-04-2007, 05:00 AM
Bookmarks