Package stdlib
Class StdIn
java.lang.Object
stdlib.StdIn
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Redirect to a file.static void
fromString
(String s) Redirect to a string.static boolean
Is the input empty (including whitespace)? Use this to know whether the next call toreadChar()
will succeed.static boolean
Does the input have a next line? Use this to know whether the next call toreadLine()
will succeed.static boolean
isEmpty()
Is the input empty (except possibly for whitespace)? Use this to know whether the next call toreadString()
,readDouble()
, etc will succeed.static void
Interactive test of basic functionality.static String
readAll()
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
readByte()
Read and return the next byte.static char
readChar()
Read and return the next character.static double
Read and return the next double.static double[]
Deprecated.static float
Read and return the next float.static int
readInt()
Read and return the next int.static int[]
readInts()
Deprecated.For more consistency, usereadAllInts()
static String
readLine()
Read and return the next line.static long
readLong()
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, usereadAllStrings()
private static void
resync()
If StdIn changes, use this to reinitialize the scanner.private static void
setScanner
(Scanner scanner)
-
Field Details
-
scanner
-
charsetName
- See Also:
-
usLocale
-
WHITESPACE_PATTERN
-
EMPTY_PATTERN
-
EVERYTHING_PATTERN
-
-
Constructor Details
-
StdIn
private StdIn()
-
-
Method Details
-
isEmpty
Is the input empty (except possibly for whitespace)? Use this to know whether the next call toreadString()
,readDouble()
, etc will succeed. -
hasNextLine
Does the input have a next line? Use this to know whether the next call toreadLine()
will succeed.Functionally equivalent to
hasNextChar()
. -
hasNextChar
Is the input empty (including whitespace)? Use this to know whether the next call toreadChar()
will succeed.Functionally equivalent to
hasNextLine()
. -
readLine
Read and return the next line. -
readChar
Read and return the next character. -
readAll
Read and return the remainder of the input as a string. -
readString
Read and return the next string. -
readInt
Read and return the next int. -
readDouble
Read and return the next double. -
readFloat
Read and return the next float. -
readLong
Read and return the next long. -
readShort
Read and return the next short. -
readByte
Read and return the next byte. -
readBoolean
Read and return the next boolean, allowing case-insensitive "true" or "1" for true, and "false" or "0" for false. -
readAllStrings
Read all strings until the end of input is reached, and return them. -
readAllInts
Read all ints until the end of input is reached, and return them. -
readAllDoubles
Read all doubles until the end of input is reached, and return them. -
resync
If StdIn changes, use this to reinitialize the scanner. -
setScanner
-
readInts
Deprecated.For more consistency, usereadAllInts()
Reads all ints from stdin. -
readDoubles
Deprecated.For more consistency, usereadAllDoubles()
Reads all doubles from stdin. -
readStrings
Deprecated.For more consistency, usereadAllStrings()
Reads all Strings from stdin. -
fromFile
Redirect to a file. This is a hack to get programs to work easily in eclipse. (Added by James Riely 2012/01/12.) -
fromString
Redirect to a string. This is a hack to get programs to work easily in eclipse. (Added by James Riely 2012/01/12.) -
main
Interactive test of basic functionality.
-
readAllDoubles()