List of utility methods to do Scanner Usage
String[] | getExtensions(Scanner scanner) Function that returns the extensions available in file open into the given Scanner List<String> extensions = new ArrayList<String>(); while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.startsWith(".")) { line = line.substring(1, line.length()); if (!line.isEmpty()) { extensions.add(line); ... |
Integer | getFirstInt(String s) get First Int Scanner in = new Scanner(s).useDelimiter("[^0-9]+".intern()); if (in.hasNext()) { return in.nextInt(); } else { return null; |
String | getInput(Scanner in, String message, boolean allowNull) get Input while (true) { System.out.print(message); String input = in.nextLine(); input = input.trim(); if (input.length() > 1) { System.out.println(""); return input; if (allowNull) { System.out.println(""); return null; |
int | getInt() Returns an int from standard input, ignoring input that is not an int int anInt = 0; try { anInt = keyboard.nextInt(); } catch (InputMismatchException ex) { keyboard.nextLine(); return anInt; |
int | getInt(Scanner sc) get Int int result = sc.nextInt(); sc.nextLine(); return result; |
int | getInteger(String parameter) Get the integer value from a string. String withDots = withDot(parameter); Scanner stringScanner = new Scanner(withDots); stringScanner.useLocale(Locale.US); return stringScanner.nextInt(); |
List | getLines(String str) Returns all lines from the given string, i.e. String line = null; List<String> lines = new ArrayList<>(); if (str.isEmpty()) { lines.add(""); return lines; Scanner scanner = new Scanner(str); while (scanner.hasNextLine()) { ... |
String | getLineStartingWith(Scanner scanner, String starts) Return the line starting with starts using the given scanner. if (scanner != null) { while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); if (line.startsWith(starts)) { scanner.close(); return line; scanner.close(); return ""; |
long | getLngIn() This returns a long number from user input return sc.nextLong();
|
String | getNextInput(Scanner scan) read next input string String word = scan.nextLine();
String word2 = (word.split(SEPARATOR)[0]);
return word2.trim();
|