Results 1 to 4 of 4
  1. #1
    blackhole8746 is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Default 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:

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    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;
        }
    }

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    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

  1. Replies: 2
    Last Post: 05-05-2008, 02:56 PM
  2. Replies: 0
    Last Post: 04-23-2008, 09:15 PM
  3. Timing array loop performance
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 09:43 PM
  4. Replies: 0
    Last Post: 04-14-2008, 09:43 PM
  5. How do I create an Array of Images
    By wco5002 in forum New To Java
    Replies: 3
    Last Post: 03-21-2008, 04:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •