Array columns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Acrylic
    New Member
    • Apr 2007
    • 3

    #1

    Array columns

    Is it possible to add columns to an array using dimenion of another array ? For example i have an array..

    int[][] anArray = new int[100][20], Obviously.. it accepts 20 columns. What I want to do is to use another array to pass it into the columns for example,

    int[] anArray2 = new int[somevalue] //somevalue is an input lets say 4. Then this array pass it to 20 columns, and create 4 columns for me, later I want ot use the remaining 16 columns to pass another value (same as above) and create me lets say 10 more columns.

    Thank you
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Acrylic
    Is it possible to add columns to an array using dimenion of another array ? For example i have an array..

    int[][] anArray = new int[100][20], Obviously.. it accepts 20 columns. What I want to do is to use another array to pass it into the columns for example,

    int[] anArray2 = new int[somevalue] //somevalue is an input lets say 4. Then this array pass it to 20 columns, and create 4 columns for me, later I want ot use the remaining 16 columns to pass another value (same as above) and create me lets say 10 more columns.

    Thank you
    It certainly can be done but it involves a lot of 'mechanics' i.e. arrays can not
    be resized so you have to allocate (new) another array, one larger than the
    previous one and copy the content of the old array over to the other new array.

    Then you have to replace the old array (a row in your two dimensional array)
    by the new array.

    I prefer ArrayLists for this sort of juggling.

    kind regards,

    Jos

    Comment

    Working...