Java String可以有多长?

2020-02-13  本文已影响0人  e小e
两种表现形式
一,存在栈中
String longString = "aaa...aaa"
image.png
length为2个字节,所以理论上最多65535,但实际上编译器只允许65534
![image.png](https://img.haomeiwen.com/i8298629/159262847b897576.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
二,存在堆中
byte[] bytes = loadFromFile(new File("superLongText.txt"));
String superLongString = new String(bytes);
image.png
上一篇 下一篇

猜你喜欢

热点阅读