List of utility methods to do Scanner Usage
List | getStrings(Scanner sc, int n) get Strings List<String> result = new ArrayList<>(n); for (int i = 0; i < n; i++) { result.add(sc.nextLine()); return result; |
int | getTimeAsInt(String duration) get Time As Int if (!isValueValid(duration, PATTERN_TIME) || duration.length() == 0) { throw new IllegalArgumentException(duration + " is not a time type"); if (duration.endsWith(":")) { duration += " "; Scanner s = new Scanner(duration); int res = 0; ... |
String | getTypedValue(String question) get Typed Value System.out.println(question);
String msgRead = scan.nextLine();
return msgRead;
|
String | input(String message) input out(NEW_LINE, message + ": "); return scanner.nextLine(); |
String | input(String prompt) input String input; System.out.println(prompt); Scanner scanner = new Scanner(System.in); input = scanner.nextLine(); return input.trim(); |
boolean | isInteger(String s) is Integer return isInteger(s, 10);
|
boolean | isNumeric(String str) is Numeric Scanner scanner = new Scanner(str); boolean flag = scanner.hasNextInt(); scanner.close(); return flag; |
boolean | isValueValid(String value, String pattern) is Value Valid Scanner s = new Scanner(value); try { s.next("^(" + pattern + ")$"); return true; } catch (InputMismatchException ex) { return false; |
boolean | isYes(String str) is Yes return getYesNoAsInt(str) == 1 ? true : false;
|
Iterable | iterate(final String node) Returns an Iterable over a node's path components. return new Iterable<String>() { @Override public Iterator<String> iterator() { return new Scanner(node).useDelimiter("/"); }; |