3 ms·
> Java arrays can have 0 dimensions The way you've phrased it is a bit ambiguous. Having 0 dimension sounds like x = new int[7][5]; // 2 dimensions y
by adrianmsmith 3y ago
> Java arrays can have 0 dimensions
The way you've phrased it is a bit ambiguous.
Having 0 dimension sounds like
x = new int[7][5]; // 2 dimensions
y = new int[9]; // 1 dimension
z = new int; // no dimensions, not an array, not allowed
The phrasing you mean is "dimensions can have zero size".
- eternalvoyage 3y agoThanks for the clarification.
- xdavidliu 3y agoUnfortunately the article author uses the exact same terminology: > (It’s somewhat counterintuitive that the zero dimension is not the first one in the array.)
- Izkata 3y agoNo, this is a quirk of the English language that I'm not sure how to describe generally. Best I can do: "Dimensions" plural agrees with "zero" as a count, so that reads as "the count of dimensions is zero". But they used singular "dimension" with "the" which treats "zero" as an adjective. It means "the dimension that is zero".
- a1369209993 3y ago> "Dimensions" plural agrees with "zero" as a count, so that [always?] reads as "the count of dimensions is zero". Out of curiosity, how do you rate each of: "Arrays can have a zero dimension." "Arrays can have two zero dimensions." "Arrays can have some zero dimensions." "Arrays can have zero dimensions." in this regard?
- Izkata 3y agoThe first three I read like "__ dimensions that are zero", the last one useless/borderline gibberish - it sounds like "isn't that just an int, not an array of ints?" So yeah, my description above is a bit off, I guess it's the articles that do it? Is "some" considered an article?
- a1369209993 3y ago> "isn't that just an int, not an array of ints?" A two-dimensional (int[x][y] not int[]...[2]...[]) "array of" int isn't really a array of ints either - it's a array of arrays of int. So a zero-dimensional "array of" int is a int. I'd call the last one ambiguous: it's either a group of (dimensions that are zero), or a (group of dimensions) that is [of group size] zero, and the text doesn't provide enough information to know which without context, just like "I read books." when you don't whether someone's talking about their hobbies or what they did over the summer.