java 无法打印,无法在Java中打印非常大的字符串(在Eclipse和cmd中均不能)

I am working with very large strings whose length range from 0 to 2*10^5.

When I try to print the strings on the console or using command line via System.out.println, nothing shows up. Only strings/substrings with 4096 characters show up. Also, I get no errors.

I also tried to print the characters one at a time using System.out.print(chararray[i]) but to no avail.

I even tried tried to use the below but it did not work.

StringWriter stringWriter = new StringWriter();

BufferedWriter bufferedWriter = new BufferedWriter(stringWriter);

bufferedWriter.write(str); //does not display

StringBuilder sb = new StringBuilder(str);

System.out.println(sb); //does not display

Displaying is important here since I am submitting my program on HackerRank and my program does not pass the test case due to this issue.

Can anyone please help?

Note: I know the strings are being stored properly since I was able to verify their lengths using str.length();

解决方案

By default, Eclipse limits the amount of text in the console output

window. So if you are running a program which produces a lot of

output, the Console will only display the last n lines and you lose

the rest.

Here is a tip which will allow you to have unlimited output in the

console:

Go to Window > Preferences > Run/Debug > Console

Uncheck "Limit Console Output" (Alternatively you can increase the Console buffer size.)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值