[英]Can String hold greater than Integer.MAX_VALUE number of character
If I want to create a String object which contains x number of character, where x > Integer.MAX_VALUE, can I do that? 如果我想创建一个包含x个字符的String对象,其中x> Integer.MAX_VALUE,我可以这样做吗?
Thanks. 谢谢。
Instead of storing a single String of length 2 bn (This will use 8 GB of memory to create btw) You can create a collection of Strings. 而不是存储长度为2 bn的单个字符串(这将使用8 GB的内存来创建btw)您可以创建字符串集合。 Its not as easy to work with but can effectively be any length. 它不是那么容易使用,但可以有效地使用任何长度。
Since String in java is a reference type, strings are stored in a contiguous block of memory. 由于java中的String是引用类型,因此字符串存储在连续的内存块中。 this block must be accessible by integer indices. 必须可以通过整数索引访问此块。 The memory range must be between 0 and 2^32 -1 in a 32 bits computer architecture which is equal to int primitive data type range. 在32位计算机体系结构中,存储器范围必须在0和2 ^ 32 -1之间,该体系结构等于int原始数据类型范围。
A basic integer data type can address your memory range. 基本整数数据类型可以解决您的内存范围。 Therefore, you can not store any string which exceeds your memory. 因此,您不能存储超出内存的任何字符串。
In addition, you can not store any data which exceeds your program stack which is very limited range of memory compared to system memory. 此外,您不能存储超出程序堆栈的任何数据,与系统内存相比,这是非常有限的内存范围。 you will get stackOverFlow exception when the application memory is exceeded. 超出应用程序内存时,您将获得stackOverFlow异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.