I remember, recently here was a topic where someone was asking about why arrays can't have long sizes. Well, it's obvious, that we can't write, say, new byte[longValueGoesHere]. But what would happen if we execute the following code:
ByteArrayOutputStream stream = new ByteArrayOutputStream(); byte[] array = new byte[Integer.MAX_VALUE]; stream.write(array); stream.write(array); byte[] bigArray = stream.toByteArray(); System.out.println(bigArray.length);
I can't do this experiment on my machine, 'cause Integer.MAX_VALUE > 2,000,000,000, and I don't have 2 GB of memory to organize sufficient heap.