So apparently in java you can resize an inner array of a 2 dimensional array. :rant:
public class Test {
public static void main(String[] args){
int [][] a=new int [4][5]; //Creating the initial array of 4x5
a[0]=new int[6]; //Resizing an array inside of the 2d array
System.out.println(a[0].length); //This will print 6.
System.out.println(a[1].length); //This will print 5
System.out.println(a.length); //This will print 4
}
}
Which I had no clue was even possible and thus, I ended up losing some points on my final in a cs class. :'(
So the question is can you do this in Glbasic? Or for that matter c/c++?
LOCAL a[]
DIM a[4][5]
...
REDIM a[7][7]
Like this?
Yes, in Java you don't have real multidimensional arrays. What you do to simulate them is creating an array in which every position contains another array, and thus you can refer to them the same way you do with 2d arrays in GLBasic or C. Since they are independent from each other, every sub-array can have a different length.
As far as I know you can't have an "array of arrays" in GLBasic.
You can do this with an array of types, which contains an array.
Quote
LOCAL a[]
DIM a[4][5]
...
REDIM a[7][7]
Like this?
Not exactly, I was referring more to staggered arrays, and was just curious to know if they were possible in glb. (In no way is this a request, as I really have no use for a staggered array, and love glb just the way it is :) .)
Quote from: Ruidesco on 2011-Dec-16
Yes, in Java you don't have real multidimensional arrays. What you do to simulate them is creating an array in which every position contains another array, and thus you can refer to them the same way you do with 2d arrays in GLBasic or C. Since they are independent from each other, every sub-array can have a different length.
As far as I know you can't have an "array of arrays" in GLBasic.
Yeah, I found this out after putting down the wrong answer on my CS final. F!@#$#n' java, oh how I hate your modern age approach to arrays. :rant:
...JK, I don't really hate java that much, I actually love it in a love/hate sort of way, after all, how can I stay mad at it when it allows for things such as inheritance. :doubt: