HopefullyHelpful HopefullyHelpful - 2 years ago 100
Java Question

StringBuilder.toString returns empty string when too big?

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++) {

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

Answer Source

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


instead, it will print what you expect (786432).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download