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

I meant something like this:

for (x=0; x Order ("order"+x)=new Order (); /// this line is wrong...
}

...so, what's the right syntax for "variable" identifiers? I hope you understand my question.

I know this is possible in Java. I forgot how it is done. I dunno where to find the answer because I don't even know what this is called.

2007-08-15 01:55:08 · 2 answers · asked by Melzy 2 in Computers & Internet Programming & Design

My bad! You misinterpreted it. Yah. It does look like I'm after arrays. No, that's not what I meant. How should I explain it? Errr...I want to make an identifier with part of it defined ("orders") and part of it depends on a variable(x). Like the identifier's name would be "orders" + x. I hope you guys get it. T_T. Uhmm..Adobe's Flash's Actionscript is capable of having this kind of identifier. I really believe that Java can do it.

2007-08-15 04:14:17 · update #1

2 answers

For something like that, you'd use a HashMap, keyed by the name:

Map orderMap = new HashMap();
orderMap.put("order0", new Order());
...

2007-08-15 05:27:21 · answer #1 · answered by McFate 7 · 0 0

It is not at all clear what you are asking, but I will guess that you are thinking about an array.

int orders = 1000;
Order[] order_list = new Order[orders];
for (int x = 0; x < orders; x++) {
order_list[x] = new Order();
}

2007-08-15 03:57:46 · answer #2 · answered by Rob C 3 · 0 0

fedest.com, questions and answers