当太大时,StringBuilder.toString()在Eclipse控制台中打印为空字符串吗? [英] StringBuilder.toString() is printed as empty string in Eclipse-console when too big?

查看:82
本文介绍了当太大时,StringBuilder.toString()在Eclipse控制台中打印为空字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下在日食中对我没有任何回报,这是预期的行为吗?

The following returns nothing for me in eclipse, is this expected behaviour ?

StringBuilder sb = new StringBuilder("");
for(int i = 0; i < 256*256*2*6; i++) {
   sb.append("a");
}
System.out.println(sb.toString());

返回的代码没有错误,并且具有良好的内存容量,与不同stringbuilder可以容纳的最大字符数

The code returns without error and the size is well withhin memory capacity unlike in Maximum number of characters stringbuilder can accommodate

已解决:问题出在Eclipse控制台上,启用(窗口->首选项->运行/调试->控制台->固定宽度控制台)将正常打印该行.

Solved: The problem lies in the eclipse console and enabling (Window -> Preferences -> Run/Debug -> Console -> fixed width console) will print the line normally.

推荐答案

问题可能出在您的控制台无法打印这么长的字符串.如果您尝试:

The problem is probably your console being unable to print such a long string. If you try:

System.out.println(sb.toString().length());

相反,它将打印您期望的内容(786432).

这篇关于当太大时,StringBuilder.toString()在Eclipse控制台中打印为空字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆