Package stdlib

Class StdIn

java.lang.Object
stdlib.StdIn

public final class StdIn extends Object
Standard input. This class provides methods for reading strings and numbers from standard input. See Section 1.5 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.

See the technical information in the documentation of the In class, which applies to this class as well.

  • Field Details Link icon

  • Constructor Details Link icon

  • Method Details Link icon

    • isEmpty Link icon

      public static boolean isEmpty()
      Is the input empty (except possibly for whitespace)? Use this to know whether the next call to readString(), readDouble(), etc will succeed.
    • hasNextLine Link icon

      public static boolean hasNextLine()
      Does the input have a next line? Use this to know whether the next call to readLine() will succeed.

      Functionally equivalent to hasNextChar().

    • hasNextChar Link icon

      public static boolean hasNextChar()
      Is the input empty (including whitespace)? Use this to know whether the next call to readChar() will succeed.

      Functionally equivalent to hasNextLine().

    • readLine Link icon

      public static String readLine()
      Read and return the next line.
    • readChar Link icon

      public static char readChar()
      Read and return the next character.
    • readAll Link icon

      public static String readAll()
      Read and return the remainder of the input as a string.
    • readString Link icon

      public static String readString()
      Read and return the next string.
    • readInt Link icon

      public static int readInt()
      Read and return the next int.
    • readDouble Link icon

      public static double readDouble()
      Read and return the next double.
    • readFloat Link icon

      public static float readFloat()
      Read and return the next float.
    • readLong Link icon

      public static long readLong()
      Read and return the next long.
    • readShort Link icon

      public static short readShort()
      Read and return the next short.
    • readByte Link icon

      public static byte readByte()
      Read and return the next byte.
    • readBoolean Link icon

      public static boolean readBoolean()
      Read and return the next boolean, allowing case-insensitive "true" or "1" for true, and "false" or "0" for false.
    • readAllStrings Link icon

      public static String[] readAllStrings()
      Read all strings until the end of input is reached, and return them.
    • readAllInts Link icon

      public static int[] readAllInts()
      Read all ints until the end of input is reached, and return them.
    • readAllDoubles Link icon

      public static double[] readAllDoubles()
      Read all doubles until the end of input is reached, and return them.
    • resync Link icon

      private static void resync()
      If StdIn changes, use this to reinitialize the scanner.
    • setScanner Link icon

      private static void setScanner(Scanner scanner)
    • readInts Link icon

      @Deprecated public static int[] readInts()
      Deprecated.
      For more consistency, use readAllInts()
      Reads all ints from stdin.
    • readDoubles Link icon

      @Deprecated public static double[] readDoubles()
      Deprecated.
      For more consistency, use readAllDoubles()
      Reads all doubles from stdin.
    • readStrings Link icon

      @Deprecated public static String[] readStrings()
      Deprecated.
      For more consistency, use readAllStrings()
      Reads all Strings from stdin.
    • fromFile Link icon

      public static void fromFile(String filename)
      Redirect to a file. This is a hack to get programs to work easily in eclipse. (Added by James Riely 2012/01/12.)
    • fromString Link icon

      public static void fromString(String s)
      Redirect to a string. This is a hack to get programs to work easily in eclipse. (Added by James Riely 2012/01/12.)
    • main Link icon

      public static void main(String[] args)
      Interactive test of basic functionality.