From 4872140b54608b28d89f546894c17026b815ae01 Mon Sep 17 00:00:00 2001 From: Omooo <869759698@qq.com> Date: Thu, 9 Apr 2020 09:00:43 +0800 Subject: [PATCH] Update String.md --- blogs/Java/String.md | 24 ++++++++++++++++++++++++ blogs/集合/CopyOnWriteArrayList.md | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 blogs/集合/CopyOnWriteArrayList.md diff --git a/blogs/Java/String.md b/blogs/Java/String.md index d0ccf4e..693f3fc 100644 --- a/blogs/Java/String.md +++ b/blogs/Java/String.md @@ -278,6 +278,30 @@ String str = "2333"; str.replace("2", "3") ``` +Java String 可以有多长? + +``` +// 字节码层面 +CONSTANT_Utf8_info { + u1 tag; + u2 length; + u1 bytes[length]; +} +``` + +看起来也就是可以存 65535 个字节,但是实际上呢,最多只能存 65534 个字节,原因在于: + +```java +// Javac 源码:Gen.java +private void checkStringConstant(DiagnosticPosition pos, Object constValue) { + // < 65535 + if((String)constValue.length() < Pool.MAX_STRING_LENGTH) + return; +} +``` + + + #### 参考 [String 源码浅析(一)](https://juejin.im/post/5c2588d8f265da6110371d2b) diff --git a/blogs/集合/CopyOnWriteArrayList.md b/blogs/集合/CopyOnWriteArrayList.md new file mode 100644 index 0000000..2c9e82d --- /dev/null +++ b/blogs/集合/CopyOnWriteArrayList.md @@ -0,0 +1,4 @@ +--- +CopyOnWriteArrayList +--- +