Output of System.out.println(-1) will be Integer or String?

If you follow the documentation, you find:

public void println(int x)

Prints an integer and then terminate the line. This method behaves as though it invokes print(int) and then println().

Then the print(int) documentation says:

The string produced by String.valueOf(int) is translated into bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of the write(int) method.

So it converts the integer to a String before converting that to bytes and printing it out.

Browse More Popular Posts

Leave a Comment