Code example for Scanner

Methods: hasNextLineuseDelimiter

0
 
   /** 
     * Read and return the remainder of the input as a string. 
     */ 
    public static String readAll() {
        if (!scanner.hasNextLine())
            return ""; 
 
        String result = scanner.useDelimiter(EVERYTHING_PATTERN).next();
        // not that important to reset delimeter, since now scanner is empty 
        scanner.useDelimiter(WHITESPACE_PATTERN); // but let's do it anyway
        return result;
    } 
 
 
   /** 
     * Read and return the next string. 
     */ 
    public static String readString() {
        return scanner.next();
Contextual code suggestions in your IDE  Get Codota for Java