Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Character limit for System.out.println() in Java

Is there any character limit for the output of Java's System.out.println(String x) statement?

When I try to print some XML from a web service call using System.out.println(), only a portion of it is actually printed in the console.

The XML string that I am trying to print is huge.

Why is this happening?

like image 706
TKV Avatar asked Jan 18 '12 14:01

TKV


People also ask

What is the maximum String size in Java?

Therefore, the maximum length of String in Java is 0 to 2147483647. So, we can have a String with the length of 2,147,483,647 characters, theoretically.

How many characters String can hold?

While an individual quoted string cannot be longer than 2048 bytes, a string literal of roughly 65535 bytes can be constructed by concatenating strings.

Can we write out Println in Java?

println(): As all instances of PrintStream class have a public method println(), hence we can invoke the same on out as well. This is an upgraded version of print(). It prints any argument passed to it and adds a new line to the output.


2 Answers

Are you experiencing this within Eclipse? If yes:

EDIT:

  1. Go to Window > Preferences > Run/Debug > Console
  2. Uncheck "Limit Console Output" (Alternatively you can increase the Console buffer size.)

Source

like image 155
quaylar Avatar answered Oct 06 '22 00:10

quaylar


My guess is that you only see the last part of the String because the console has a limited number of lines it can display.

Consider logging to a file from Java, or redirecting the standard output from the program to a file:

java com.foo.bar.Main > output.log
like image 38
JB Nizet Avatar answered Oct 06 '22 00:10

JB Nizet