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.

  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    fromFile(String filename)
    Redirect to a file.
    static void
    Redirect to a string.
    static boolean
    Is the input empty (including whitespace)? Use this to know whether the next call to readChar() will succeed.
    static boolean
    Does the input have a next line? Use this to know whether the next call to readLine() will succeed.
    static boolean
    Is the input empty (except possibly for whitespace)? Use this to know whether the next call to readString(), readDouble(), etc will succeed.
    static void
    main(String[] args)
    Interactive test of basic functionality.
    static String
    Read and return the remainder of the input as a string.
    static double[]
    Read all doubles until the end of input is reached, and return them.
    static int[]
    Read all ints until the end of input is reached, and return them.
    static String[]
    Read all strings until the end of input is reached, and return them.
    static boolean
    Read and return the next boolean, allowing case-insensitive "true" or "1" for true, and "false" or "0" for false.
    static byte
    Read and return the next byte.
    static char
    Read and return the next character.
    static double
    Read and return the next double.
    static double[]
    Deprecated.
    For more consistency, use readAllDoubles()
    static float
    Read and return the next float.
    static int
    Read and return the next int.
    static int[]
    Deprecated.
    For more consistency, use readAllInts()
    static String
    Read and return the next line.
    static long
    Read and return the next long.
    static short
    Read and return the next short.
    static String
    Read and return the next string.
    static String[]
    Deprecated.
    For more consistency, use readAllStrings()

    Methods inherited from class java.lang.Object

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

    • isEmpty

      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

      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

      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

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

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

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

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

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

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

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

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

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

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

      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

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

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

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

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

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

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

      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

      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

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