Since String in java is a reference type, strings are stored in a contiguous block of memory. this block must be accessible by integer indices. The memory range must be between 0 and 2 ^ 32 -1 in the 32-bit computer architecture, which is equal to the int-primitive data type.
The main integer data type can access your memory range. Therefore, you cannot save a string that exceeds your memory.
In addition, you cannot store any data that exceeds your program stack, which is a very limited memory range compared to system memory. you will get a stackOverFlow exception when the application memory is exceeded.
source share