Java Methods of PrintStream

Here are some of the commonly used methods of the PrintStream class in Java:

  1. print(boolean b): This method prints the string representation of a boolean value to the output stream.

  2. print(char c): This method prints a character to the output stream.

  3. print(int i): This method prints the string representation of an integer to the output stream.

  4. print(long l): This method prints the string representation of a long integer to the output stream.

  5. print(float f): This method prints the string representation of a float value to the output stream.

  6. print(double d): This method prints the string representation of a double value to the output stream.

  7. print(char[] s): This method prints an array of characters to the output stream.

  8. print(String s): This method prints a string to the output stream.

  9. println(): This method prints a newline character to the output stream.

  10. println(boolean b): This method prints the string representation of a boolean value to the output stream, followed by a newline character.

  11. println(char c): This method prints a character to the output stream, followed by a newline character.

  12. println(int i): This method prints the string representation of an integer to the output stream, followed by a newline character.

  13. println(long l): This method prints the string representation of a long integer to the output stream, followed by a newline character.

  14. println(float f): This method prints the string representation of a float value to the output stream, followed by a newline character.

  15. println(double d): This method prints the string representation of a double value to the output stream, followed by a newline character.

  16. println(char[] s): This method prints an array of characters to the output stream, followed by a newline character.

  17. println(String s): This method prints a string to the output stream, followed by a newline character.

  18. printf(String format, Object... args): This method prints a formatted string to the output stream using the specified format string and arguments.

  19. flush(): This method flushes the output stream.

  20. close(): This method closes the output stream and releases any system resources associated with it.

It's important to note that the PrintStream class should be used with caution when printing to untrusted destinations, as it can be vulnerable to malicious attacks if the data is not properly validated. Additionally, when using a PrintStream, you should always make sure to call the flush() method or close the stream to ensure that all the data is written to the underlying stream.