I was just writing a programming assignment in Java for a professor that is notorious for giving us ridiculous inputs in an attempt to break the code and I was thinking of a case where the user might require the construction of an array that would go over 2,147,483,647 in size. But it only takes in an int for constructor... While it is unlikely he would do that, just out of curiosity; Is there an array object in Java that would let you do so? or why it doesn't exist if not?
Asked
Active
Viewed 58 times
0
-
1Welcome to SO. Please read [ask], and show a [mcve]. Thanks! – OldProgrammer Mar 01 '17 at 23:28
-
1http://stackoverflow.com/q/3038392/5647260 – Andrew Li Mar 01 '17 at 23:29
-
@OldProgrammer Why do you think the OP hasn't given a MCVE? – nbro Mar 01 '17 at 23:29
-
You can't make arrays that big. There's an internal limit in the JVM, which is slightly less than the largest int. – Dawood ibn Kareem Mar 01 '17 at 23:31
-
Bigger arrays aren't even expressible in byte code (initial size, getting the length later, indexing into it, all impossible). If you really must, you could have an array of arrays and do two-step indexing – harold Mar 01 '17 at 23:33
-
You can use a multidimensional array, which would hold `n ^ d` elements. – shmosel Mar 01 '17 at 23:34