• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An array name can be changed inside a for statement?

 
Hugo Alejandro
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!

I have this:

for (int i = 0; i < arraylist.size(); i++) {

}

I'd want to know if I can dinamically change the name of something I create inside the for statement. Something like:

for (int i = 0; i < arraylist.size(); i++) {
String "dinamicName"+i [][] = new String[x][y];
arraylist.add("dinamicName"+i);
}

I already have a static structure which make the job but I want to make it work dinamic, what can I do?
Thanks!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
variable names and such are really only used by the PROGRAMMER. therefore, it really doesn't do you any good to change the variable name. it gains you nothing, and would make your code very confusing. therefore, it can't really be done.
 
Hugo Alejandro
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thank you!
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However, you could put the data into a Map instead of a List so that you can use a String as an identifier. For example:


Then you can get the data out later:



I don't exactly know what benefit you get in that over just putting the values in the indexed ArrayList though...
[ August 05, 2008: Message edited by: Steve Luke ]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both those replies lead to the question - why do you think you need to do this ? If you explain the problem you are trying to solve, maybe someone will be able to propose a solution.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic