Package Util
Class In
java.lang.Object
Util.In
This class provides methods for input operations from various sources such as system input, files, and streams,
and supports the parsing of primitive types and strings, including array and list formats.
Can use a custom delimiter for tokenizing input strings, but uses whitespace by default
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Sahasrad Chippa
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Gets the current delimiter string used to parse tokens.static String
next()
Reads the next token from input.static BigInteger
Reads the next token and tries to parse it as aBigInteger
.static BigInteger[]
nextBigIntegerArray
(int n) Reads and returns an array of BigInteger values.static List
<BigInteger> nextBigIntegerList
(int n) Reads and returns a list of BigInteger values from the input.static boolean[]
nextBinaryString
(char truth) Reads the next token and interprets it as a binary string where each 'truth' character (typically '1') is true.static boolean
Reads the next token and tries to parse it as a boolean.static boolean[]
nextBooleanArray
(int n) Reads and returns an array of boolean values interpreted from the input.nextBooleanList
(int n) Reads and returns a list of boolean values interpreted from the input.static double
Reads the next token and tries to parse it as a double.static double[]
nextDoubleArray
(int n) Reads and returns an array of double values from the input.nextDoubleList
(int n) Reads and returns a list of double values from the input.static int
nextInt()
Reads the next token and tries to parse it as an int.static int[]
nextIntArray
(int n) Reads and returns an array of integers from the input.nextIntList
(int n) Reads and returns a list of integers from the input.static String
nextLine()
Reads until the end of the current line and returns all remaining tokens as a single string.static long
nextLong()
Reads the next token and tries to parse it as a long.static long[]
nextLongArray
(int n) Reads and returns an array of long integers from the input.nextLongList
(int n) Reads and returns a list of long integers from the input.static String[]
nextStringArray
(int n) Reads and returns an array of strings from the input.nextStringList
(int n) Reads and returns a list of strings from the input.static boolean
setDelimiter
(String delim) Sets a new delimiter for tokenizing input strings.static void
setFileInput
(String fileName) Sets the input source to a file via its filename.static void
setInput
(InputStream in) Sets the input source to a specificInputStream
.
-
Constructor Details
-
In
public In()
-
-
Method Details
-
getDelimiter
Gets the current delimiter string used to parse tokens.- Returns:
- The string representing current delimiters.
-
setDelimiter
Sets a new delimiter for tokenizing input strings.- Parameters:
delim
- The string containing delimiter characters.- Returns:
- True if there are no more tokens to process from current input line, false otherwise.
-
setInput
Sets the input source to a specificInputStream
.- Parameters:
in
- The input stream to read from.
-
setFileInput
Sets the input source to a file via its filename.- Parameters:
fileName
- The name of the file to read from.- Throws:
IllegalArgumentException
- if a file withfileName
cannot be found.
-
next
Reads the next token from input.- Returns:
- The next token as a String
- Throws:
NoSuchElementException
- if no more tokens are available or an error occurs.
-
nextInt
public static int nextInt()Reads the next token and tries to parse it as an int.- Returns:
- The parsed int.
-
nextLong
public static long nextLong()Reads the next token and tries to parse it as a long.- Returns:
- The parsed long.
-
nextDouble
public static double nextDouble()Reads the next token and tries to parse it as a double.- Returns:
- The parsed double.
-
nextBigInteger
Reads the next token and tries to parse it as aBigInteger
.- Returns:
- The parsed
BigInteger
.
-
nextBoolean
public static boolean nextBoolean()Reads the next token and tries to parse it as a boolean.- Returns:
- The parsed boolean.
-
nextBinaryString
public static boolean[] nextBinaryString(char truth) Reads the next token and interprets it as a binary string where each 'truth' character (typically '1') is true.- Parameters:
truth
- The character interpreted as true.- Returns:
- An array of booleans representing the binary string.
-
nextLine
Reads until the end of the current line and returns all remaining tokens as a single string.- Returns:
- The complete line or remaining tokens fused into one line.
-
nextStringArray
Reads and returns an array of strings from the input.- Parameters:
n
- The number of strings to read.- Returns:
- A string array containing the read strings.
-
nextIntArray
public static int[] nextIntArray(int n) Reads and returns an array of integers from the input.- Parameters:
n
- The number of integers to read.- Returns:
- An integer array containing the read integers.
-
nextLongArray
public static long[] nextLongArray(int n) Reads and returns an array of long integers from the input.- Parameters:
n
- The number of long integers to read.- Returns:
- A long integer array containing the read long integers.
-
nextDoubleArray
public static double[] nextDoubleArray(int n) Reads and returns an array of double values from the input.- Parameters:
n
- The number of double values to read.- Returns:
- A double array containing the read values.
-
nextBigIntegerArray
Reads and returns an array of BigInteger values.- Parameters:
n
- The number of BigInteger values to read.- Returns:
- An array of BigInteger values.
-
nextBooleanArray
public static boolean[] nextBooleanArray(int n) Reads and returns an array of boolean values interpreted from the input.- Parameters:
n
- The number of boolean values to read.- Returns:
- A boolean array containing the read values.
-
nextStringList
-
nextIntList
-
nextLongList
-
nextDoubleList
-
nextBigIntegerList
Reads and returns a list of BigInteger values from the input.- Parameters:
n
- The number of BigInteger values to read.- Returns:
- A list containing the read BigInteger values.
-
nextBooleanList
-