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

  • Constructor Details

  • 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.
    • resync

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

      private static void setScanner(Scanner scanner)
    • 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.