Java Methods of PrintStream
Here are some of the commonly used methods of the PrintStream
class in Java:
print(boolean b)
: This method prints the string representation of a boolean value to the output stream.print(char c)
: This method prints a character to the output stream.print(int i)
: This method prints the string representation of an integer to the output stream.print(long l)
: This method prints the string representation of a long integer to the output stream.print(float f)
: This method prints the string representation of a float value to the output stream.print(double d)
: This method prints the string representation of a double value to the output stream.print(char[] s)
: This method prints an array of characters to the output stream.print(String s)
: This method prints a string to the output stream.println()
: This method prints a newline character to the output stream.println(boolean b)
: This method prints the string representation of a boolean value to the output stream, followed by a newline character.println(char c)
: This method prints a character to the output stream, followed by a newline character.println(int i)
: This method prints the string representation of an integer to the output stream, followed by a newline character.println(long l)
: This method prints the string representation of a long integer to the output stream, followed by a newline character.println(float f)
: This method prints the string representation of a float value to the output stream, followed by a newline character.println(double d)
: This method prints the string representation of a double value to the output stream, followed by a newline character.println(char[] s)
: This method prints an array of characters to the output stream, followed by a newline character.println(String s)
: This method prints a string to the output stream, followed by a newline character.printf(String format, Object... args)
: This method prints a formatted string to the output stream using the specified format string and arguments.flush()
: This method flushes the output stream.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.