gpt4 book ai didi

java - StringBuffer 的容量是多少?

转载 作者:搜寻专家 更新时间:2023-10-30 21:16:46 25 4
gpt4 key购买 nike

当我运行这段代码时:

StringBuffer name = new StringBuffer("stackoverflow.com");
System.out.println("Length: " + name.length() + ", capacity: " + name.capacity());

它给出输出:

Length: 17, capacity: 33

明显的长度与字符串的字符数有关,但我不确定容量是多少?StringBuffer 在重新分配空间之前可以容纳的字符数是多少?

最佳答案

参见:JavaSE 6 java.lang.StringBuffer capacity()

但是你的假设是正确的:

The capacity is the amount of storage available for newly inserted characters, beyond which an allocation will occur

关于java - StringBuffer 的容量是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8011574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com