Java Scanner hasNextByte() method example

HQ ┬╗ Java Tutorial ┬╗ java.util ┬╗ Scanner ┬╗ hasNextByte() method example
Java Scanner hasNextByte() method example 2018-02-20T12:08:31+00:00

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 :

DataType Parameter Description

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 :


Contact Info


Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.