Java ScannerhasNextFloat() Method
Example
Print the value of every floating point number in the string:
// Create a scanner objectScanner myObj = new Scanner("The probability is 45.6 percent");// Print the value of every floating point number in the scannerwhile (myObj.hasNext()) { if (myObj.hasNextFloat()) { System.out.println(myObj.nextFloat()); } else { myObj.next(); }}Definition and Usage
ThehasNextFloat() method returnstrue if the next token represents a valid number.
The scanner is able to interpret digit groupings, such as using a comma for separating groups of 3 digits. The format of the groupings and the character used as a decimal point depend on the locale settings of the scanner, which can be changed with theuseLocale() method.
What is a token?
A token is a sequence of characters separated from other tokens by delimiters. The default delimiter is a block of whitespace characters but it can be changed with theuseDelimiter() method.
Syntax
public boolean hasNextFloat()Technical Details
| Returns: | Aboolean value which is true if the next token represents a valid number. |
|---|---|
| Throws: | IllegalStateException - If the scanner has been closed. |

