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

ListjoinSqlStatements(Collection scripts)
join Sql Statements
List<String> scriptList = new ArrayList<String>();
for (String script : scripts) {
    script = script.trim();
    StringBuilder sb = new StringBuilder();
    boolean blankLine = false;
    Scanner scanner = new Scanner(script);
    while (scanner.hasNextLine()) {
        String temp = scanner.nextLine();
...
charleerOpcion(String opciones, String msgUsr, String msgErr)
leer Opcion
char dato = 0;
boolean lecturaOK = false;
do {
    try {
        System.out.print(msgUsr);
        dato = SCN.nextLine().charAt(0);
        if (opciones.contains(dato + "")) {
            lecturaOK = true;
...
StringleerTexto(String msgUsr)
leer Texto
System.out.print(msgUsr);
return SCN.nextLine();
String[]listify(String s, String prefix, String... ignorelist)
listify
ArrayList<String> l = new ArrayList<String>();
Scanner m = new Scanner(s);
while (m.hasNextLine()) {
    String b = m.nextLine().trim();
    if (b.length() <= 0)
        continue;
    l.add(prefix + b);
if (ignorelist.length > 0) {
    ArrayList<String> x = new ArrayList<String>();
    for (String a : l) {
        boolean good = true;
        for (String bad : ignorelist) {
            if (!a.contains((CharSequence) bad))
                continue;
            good = false;
        if (!good)
            continue;
        x.add(a);
    l = x;
return l.toArray(new String[0]);
String[]listify(String s, String prefix, String... ignorelist)
Parses a String, assumed to be a list, into a String array.
ArrayList<String> l = new ArrayList<String>();
Scanner m = new Scanner(s);
while (m.hasNextLine()) {
    String b = m.nextLine().trim();
    if (b.length() > 0)
        l.add(prefix + b);
if (ignorelist.length > 0) {
...
ArrayListloadElements(Scanner scan, int elementCount, int skipCount)
load Elements
ArrayList<Integer> sequence;
if (elementCount > 0) {
    sequence = new ArrayList<>(elementCount);
} else {
    sequence = new ArrayList<>();
while (scan.hasNextInt() && skipCount-- != 0) {
    scan.nextInt();
...
HashMaploadStringDoubleMap(Scanner scanner)
load String Double Map
HashMap<String, double[]> ret = new HashMap<String, double[]>();
int dimX = scanner.nextInt();
int dimY = scanner.nextInt();
scanner.nextLine();
for (int i = 0; i < dimX; i++) {
    String word = scanner.nextLine();
    double[] vals = new double[dimY];
    for (int j = 0; j < dimY; j++) {
...
intmenu()
menu
int selection;
Scanner input = new Scanner(System.in);
System.out.println("Please enter a number to perfom the desired operation");
System.out.println("-------------------------\n");
System.out.println("1 - Call the international geocoding API provided by PostCodeAnywhere (SOAP)");
System.out.println("2 - Call the global weather API provided by WorldWeatherOnline (REST)");
System.out.println("3 - Quit");
selection = input.nextInt();
...
charnextChar(Scanner s)
read exactly one character from the scanner from: http://stackoverflow.com/a/13942707/1066911
return s.findInLine(".").charAt(0);
intnextInt(final Scanner sc)
next Int
try {
    return sc.nextInt();
} catch (final InputMismatchException ime) {
    return 0;