Just a quick question – if I instantiate a new two dimensional int array like so
int[][] input = new int[101][]; //number is irrelevant
eclipse seems to not mind this, but I’m not entirely sure if this would work like I’m expecting it to, which is that the second part of the array would act dynamically.
after reading your answers, I realise that my question is badly worded.
I am reading in from a file – it is a CSV and there is 101 columns and X amount of rows. Since I am reading the file in line-by-line, it is simple for me to figure out that the first dimension of my “2-d array” is 101. But, also because I am reading the file line-by-line, I cannot say for certain that my second dimension will be X without iterating through the entire file.
How would I find X using my current method, or is that actually impossible?
Then you’d have 101 elements in
inputwhich are allnull. To create the second dimension, you’d need to initialize it for every item:The second dimension doesn’t need to be the same for all first level items. The second dimension would be the same if you used this:
All values would then be initialized to
0.But the real answer is: Why didn’t you just try?