aspose file tools*
The moose likes Beginning Java and the fly likes An array name can be changed inside a for statement? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "An array name can be changed inside a for statement?" Watch "An array name can be changed inside a for statement?" New topic
Author

An array name can be changed inside a for statement?

Hugo Alejandro
Greenhorn

Joined: Jul 31, 2008
Posts: 11
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

Joined: Oct 02, 2003
Posts: 11422
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Hugo Alejandro
Greenhorn

Joined: Jul 31, 2008
Posts: 11
Ok, thank you!
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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 ]

Steve
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3682
    
  16
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.


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: An array name can be changed inside a for statement?