what is the difference between System.out.write and System.out.print in java [closed]


I want to know where is the difference between System.out.write and System.out.print in my Java class.


Answers:


The two methods of PrintStream have different meanings:

  • print(int) writes a decimal representation of the entire int, while
  • write(int) writes the least significant byte of the specified int to the output.

This leads to different results: if you call print(48), the output is going to be 48, but if you call write(48), the output would be system-dependent, but on most systems it would be 0.

Demo.