Results 1 to 4 of 4
- 05-07-2008, 01:31 AM #1
Member
- Join Date
- Mar 2008
- Posts
- 2
- Rep Power
- 0
How do I create an array with every cycle of a loop?
Suppose I wanted to create a new array with every loop? The arrays created have to have different names like a1, a2, a3 etc. Anything will do.
The code goes like
for(int i = 0; i < 9; i++){
int[] a/*The index goes here*/ = new int [9]
}
Can I do such a thing? :confused:
- 05-07-2008, 03:25 AM #2
Java Code:int[][] allArrays = new int[9][]; for(int i = 0; i < allArrays.length; i++){ int n = any_int_value; allArrays[i] = new int[n]; for(int j = 0; j < allArrays[i].length; j++) { allArrays[i][j] = some_int_value; } }
- 05-07-2008, 06:35 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You want to dynamically change the array name here. Isn't it?
- 05-07-2008, 07:49 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Waiting for response. ;)
Anyway I don't think in an arrays we can do it. You had to have the array name somewhere in your application already define.
How about HashMap. May be you can use it different way. But I don't know exactly what is your requirements.
Similar Threads
-
Need another program with and if-else, array, and for loop
By Zebra in forum New To JavaReplies: 2Last Post: 05-05-2008, 01:56 PM -
Using reflection to create, fill, and display an array
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:15 PM -
Timing array loop performance
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:43 PM -
Using reflection to create, fill, and display an array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:43 PM -
How do I create an Array of Images
By wco5002 in forum New To JavaReplies: 3Last Post: 03-21-2008, 03:45 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks