Java Utililty Methods Scanner Usage

List of utility methods to do Scanner Usage

Description

The list of methods to do Scanner Usage are organized into topic(s).

Method

ScannercreateKeyboardScanner()
Creates and returns a Scanner that can be used to read from the keyboard.
return new Scanner(System.in);
ScannercreateScannerForString(String s)
Creates a Scanner that can be used to read directly from a given text string.
return new Scanner(s);
voidenterToContinue()
enter To Continue
Scanner scanner = new Scanner(System.in);
System.out.println("Press enter to continue.");
scanner.nextLine();
booleanequalsToIgnoreEndline(String expected, String actual)
compares two strings for equality, line by line, ignoring any difference of end line delimiters contained within the 2 Strings.
if (expected == null && actual == null) {
    return true;
if (expected != null ^ actual != null) {
    return false;
Scanner scanner1 = new Scanner(expected);
Scanner scanner2 = new Scanner(actual);
...
StringfromStringToQuery(String value)
from String To Query
String query = "";
boolean isOpenedQuote = false;
Scanner sc = new Scanner(value);
while (sc.hasNext()) {
    String next = sc.next();
    if (next.contains("\"") || isOpenedQuote) {
        query += next;
        if (next.contains("\"")) {
...
booleangetBoolean()
get Boolean
char c = commandLine.nextLine().toLowerCase().trim().charAt(0);
return 't' == c;
chargetChar()
get Char
char choice;
String line = commandLine.nextLine().toLowerCase().trim();
if (line.length() == 0) {
    choice = ' ';
} else
    choice = line.charAt(0);
return choice;
List>getConstantPoolsFromText(String text)
get Constant Pools From Text
Scanner scanner = new Scanner(text);
scanner.nextLine(); 
List<List<String>> result = new ArrayList<>();
List<String> cPool = new ArrayList<>();
result.add(cPool);
while (scanner.hasNextLine()) {
    String line = scanner.nextLine();
    if (line.startsWith("---")) {
...
StringgetDirectoryString()
get Directory String
String sep = System.getProperty("path.separator");
String dir = commandLine.nextLine().toLowerCase().trim();
if (dir.charAt(dir.length() - 1) != sep.charAt(0)) {
    dir += sep;
return dir;
intgetEndLine(String cqlString)
get End Line
System.out.println("Get end line");
Scanner scanner = new Scanner(cqlString);
int endLine = -1;
while (scanner.hasNextLine()) {
    endLine++;
    scanner.nextLine();
return endLine;
...