Java Scanner hasNextBigInteger() Method

The hasNextBigInteger() is a Java Scanner class method which is used to check the next token in this scanner's input can be interpreted as a BigInteger value in the default radix or not. It returns true if it is interprated as a BigInteger value, otherwise returns false. There is two different types of Java hasNextBigInteger() method which can be differentiated depending on its parameter. These are:

  1. Java Scanner hasNextBigInteger() Method
  2. Java Scanner hasNextBigInteger(int radix) Method

hasNextBigInteger() Method:

This is a Java Scanner class method which is used to check the next token in this scanner's input can be interpreted as a BigInteger value in the default radix using the nextBigInteger() method.

hasNextBigInteger(int radix) Method:

This is an inbuilt method of Java Scanner class which is used to check the next token in this scanner's input can be interpreted as a BigInteger value in the specified radix using the nextBigInteger() method.

Syntax

Following is the declaration of hasNextBigInteger() method:

Parameter

DataTypeParameterDescriptionRequired/Optional
intradixIt is used to interpret the token as an Integer value.Required

Returns

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

Exceptions

IllegalStateException- This method throws exception if the innvocation is done after the scanner has been closed.

IllegalArgumentException- It throws this exception if the specified radix is out of range.

Compatibility Version

Java 1.5 and above

Example 1

Output:

Found Integer Value: 22
Not Found Integer Value: Double
Found Integer Value: 75
Not Found Integer Value: number
Not Found Integer Value: is
Not Found Integer Value: 2123324.58

Example 2

Output:

Exception in thread "main" java.lang.IllegalArgumentException: radix:598670
	at java.base/java.util.Scanner.setRadix(Scanner.java:1368)
	at java.base/java.util.Scanner.nextBigInteger(Scanner.java:2673)
	at myPackage.ScannerHasNextBigIntegerExample2.main(ScannerHasNextBigIntegerExample2.java:9)

Example 3

Output:

Not Found :JavaTpoint.com
Found :11
Not Found :+
Found :11
Not Found :=
Not Found :22.0

Example 4

Output:

Please enter value: 3453740
Your entered value: 3453740