Package stdlib

Class StdOut

java.lang.Object
stdlib.StdOut

public final class StdOut extends Object
This class provides methods for printing strings and numbers to standard output.

Differences with System.out. The behavior of StdOut is similar to that of System.out, ut there are a few technical differences:

  • StdOut coerces the character-set encoding to UTF-8, which is a standard character encoding for Unicode.
  • StdOut coerces the locale to Locale.US, for consistency with StdIn, Double.parseDouble(String), and floating-point literals.
  • StdOut flushes standard output after each call to print() so that text will appear immediately in the terminal.

Reference. For additional documentation, see Section 1.5 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.

Author:
Robert Sedgewick, Kevin Wayne
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    main(String[] args)
    Unit tests some of the methods in StdOut.
    static void
    Flushes standard output.
    static void
    print(boolean x)
    Prints a boolean to standard output and flushes standard output.
    static void
    print(byte x)
    Prints a byte to standard output and flushes standard output.
    static void
    print(char x)
    Prints a character to standard output and flushes standard output.
    static void
    print(double x)
    Prints a double to standard output and flushes standard output.
    static void
    print(float x)
    Prints a float to standard output and flushes standard output.
    static void
    print(int x)
    Prints an integer to standard output and flushes standard output.
    static void
    print(long x)
    Prints a long integer to standard output and flushes standard output.
    static void
    print(short x)
    Prints a short integer to standard output and flushes standard output.
    static void
    Prints an object to standard output and flushes standard output.
    static void
    printf(String format, Object... args)
    Prints a formatted string to standard output, using the specified format string and arguments, and then flushes standard output.
    static void
    printf(Locale locale, String format, Object... args)
    Prints a formatted string to standard output, using the locale and the specified format string and arguments; then flushes standard output.
    static void
    Terminates the current line by printing the line-separator string.
    static void
    println(boolean x)
    Prints a boolean to standard output and then terminates the line.
    static void
    println(byte x)
    Prints a byte to standard output and then terminates the line.
    static void
    println(char x)
    Prints a character to standard output and then terminates the line.
    static void
    println(double x)
    Prints a double to standard output and then terminates the line.
    static void
    println(float x)
    Prints an integer to standard output and then terminates the line.
    static void
    println(int x)
    Prints an integer to standard output and then terminates the line.
    static void
    println(long x)
    Prints a long to standard output and then terminates the line.
    static void
    println(short x)
    Prints a short integer to standard output and then terminates the line.
    static void
    Prints an object to this output stream and then terminates the line.
    static void
    If StdOut changes, use this to reinitialize the PrintWriter.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • println

      public static void println()
      Terminates the current line by printing the line-separator string.
    • println

      public static void println(Object x)
      Prints an object to this output stream and then terminates the line.
      Parameters:
      x - the object to print
    • println

      public static void println(boolean x)
      Prints a boolean to standard output and then terminates the line.
      Parameters:
      x - the boolean to print
    • println

      public static void println(char x)
      Prints a character to standard output and then terminates the line.
      Parameters:
      x - the character to print
    • println

      public static void println(double x)
      Prints a double to standard output and then terminates the line.
      Parameters:
      x - the double to print
    • println

      public static void println(float x)
      Prints an integer to standard output and then terminates the line.
      Parameters:
      x - the integer to print
    • println

      public static void println(int x)
      Prints an integer to standard output and then terminates the line.
      Parameters:
      x - the integer to print
    • println

      public static void println(long x)
      Prints a long to standard output and then terminates the line.
      Parameters:
      x - the long to print
    • println

      public static void println(short x)
      Prints a short integer to standard output and then terminates the line.
      Parameters:
      x - the short to print
    • println

      public static void println(byte x)
      Prints a byte to standard output and then terminates the line.

      To write binary data, see BinaryStdOut.

      Parameters:
      x - the byte to print
    • print

      public static void print()
      Flushes standard output.
    • print

      public static void print(Object x)
      Prints an object to standard output and flushes standard output.
      Parameters:
      x - the object to print
    • print

      public static void print(boolean x)
      Prints a boolean to standard output and flushes standard output.
      Parameters:
      x - the boolean to print
    • print

      public static void print(char x)
      Prints a character to standard output and flushes standard output.
      Parameters:
      x - the character to print
    • print

      public static void print(double x)
      Prints a double to standard output and flushes standard output.
      Parameters:
      x - the double to print
    • print

      public static void print(float x)
      Prints a float to standard output and flushes standard output.
      Parameters:
      x - the float to print
    • print

      public static void print(int x)
      Prints an integer to standard output and flushes standard output.
      Parameters:
      x - the integer to print
    • print

      public static void print(long x)
      Prints a long integer to standard output and flushes standard output.
      Parameters:
      x - the long integer to print
    • print

      public static void print(short x)
      Prints a short integer to standard output and flushes standard output.
      Parameters:
      x - the short integer to print
    • print

      public static void print(byte x)
      Prints a byte to standard output and flushes standard output.
      Parameters:
      x - the byte to print
    • printf

      public static void printf(String format, Object... args)
      Prints a formatted string to standard output, using the specified format string and arguments, and then flushes standard output.
      Parameters:
      format - the format string
      args - the arguments accompanying the format string
    • printf

      public static void printf(Locale locale, String format, Object... args)
      Prints a formatted string to standard output, using the locale and the specified format string and arguments; then flushes standard output.
      Parameters:
      locale - the locale
      format - the the format string
      args - the arguments accompanying the format string
    • resync

      public static void resync()
      If StdOut changes, use this to reinitialize the PrintWriter.
    • main

      public static void main(String[] args)
      Unit tests some of the methods in StdOut.
      Parameters:
      args - the command-line arguments