public static void main(String[] args) {
int maxSize = Integer.MAX_VALUE - 2;
long start = System.currentTimeMillis();
StringBuilder sb = new StringBuilder(maxSize);
while (sb.length() < maxSize)
sb.append(' ');
long time = System.currentTimeMillis() - start;
System.out.println("Took " + time / 1e3 + " second to create a StringBuilder of " + sb.length());
}
这个指纹
Took 7.415 second to create a StringBuilder of 2147483645
1条答案
按热度按时间huus2vyu1#
我可以添加到stringbuilder的最大大小是integer.max\u size-2
这个指纹
这是一次只写一个字符,所以它确实需要更长的时间。