Java Scanner Usage loadElements(Scanner scan, int elementCount, int skipCount)

Here you can find the source of loadElements(Scanner scan, int elementCount, int skipCount)

Description

load Elements

License

Apache License

Declaration

protected static ArrayList<Integer> loadElements(Scanner scan, int elementCount, int skipCount) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

import java.util.Scanner;

public class Main {
    protected static ArrayList<Integer> loadElements(Scanner scan, int elementCount, int skipCount) {
        ArrayList<Integer> sequence;
        if (elementCount > 0) {
            sequence = new ArrayList<>(elementCount);
        } else {//w w  w.  ja  v  a2 s  . co m
            sequence = new ArrayList<>();
        }

        while (scan.hasNextInt() && skipCount-- != 0) {
            scan.nextInt();
        }

        while (scan.hasNextInt() && elementCount-- != 0) {
            sequence.add(scan.nextInt());
        }

        return sequence;
    }
}

Related

  1. joinSqlStatements(Collection scripts)
  2. leerOpcion(String opciones, String msgUsr, String msgErr)
  3. leerTexto(String msgUsr)
  4. listify(String s, String prefix, String... ignorelist)
  5. listify(String s, String prefix, String... ignorelist)
  6. loadStringDoubleMap(Scanner scanner)
  7. menu()
  8. nextChar(Scanner s)
  9. nextInt(final Scanner sc)