Javatpoint Logo
Javatpoint Logo

Java Scanner hasNextBoolean() Method

The hasNextBoolean() is a method of Java Scanner class which is used to check if the next token in this scanner's input can be interpreted as a boolean value using a case insensitive pattern created from the string "true/false". It returns true if the scanner's input can be interpreted as a boolean value, otherwise returns false.

Syntax

Following is the declaration of hasNextBoolean() method:

Parameter

This method does not accept any parameter.

Returns

The hasNextBoolean() method returns true if and only if this scanner's next token is a valid boolean value.

Exceptions

IllegalStateException

Compatibility Version

Java 1.5 and above

Example 1

Output:

Result: false
Scan String: JavaTpoint.com!

Example 2

Output:

Result: true
Scan String: false

Example 3

Output:

Please enter value: true
Your entered value: true

Example 4

Output:

false
Hello
false
JavaTpoint!
false
13
false
+
false
13.0
false
=
false
26

Next TopicJava Scanner Class



Help Others, Please Share

facebook twitter pinterest