java.util.Scanner hasNextByte()

Description :

This java tutorial shows how to use the hasNextByte method of Scanner class of java.util package. This method returns true if the next byte on the scanner buffer can be translated to byte data type otherwise false.

Method Syntax :

public boolean hasNextByte()

Parameter Input :


Method Returns :

This method simply returns a boolean data type which corresponds to the scanner token that can be interpreted as byte. Return true if next token is byte otherwise false.

Compatibility Version :

Requires Java 1.5 and up

Exception :


– the method hasNextByte method will throw this exception if the invocation is done after the scanner is already closed.

Discussion :

The Scanner hasNextByte() method to scans and check if the tokens contains a byte data type. To give an overview on byte data type, the maximum value to be considered a byte is 127 and minimum value is -128.

Java Code Example :

This java example source code demonstrates the use of hasNextByte method of Scanner class. Basically the code just checks if the tokens contains a byte.

Sample Output :

Running the hasNextByte() method example source code of Scanner class will give you the following output

java scanner hasnextbyte method example

java scanner hasnextbyte method example

Exception Scenario :

Similar Method :

  • N/A

Suggested Reading List :

References :