Java Scanner match() MethodThe match() method of Java Scanner class is used to get the match result of the last scanning operation performed by this scanner. It returns true if it find the match result, otherwise returns false. SyntaxFollowing is the declaration of match() method: ParameterThis method does not accept any parameter. ReturnsThe match() method returns a match result for the last match operation. ExceptionsIllegalStateException- This method thrown Exception if no match result is available. Compatibility VersionJava 1.5 and above Example 1Output: Scan String True/False: true Last Match String: [email protected] Hello World! 123 JTP Example 2Output: Radix:16 Pattern match at index:0 Pattern match at index:2 Pattern match at index:4 Pattern match at index:6 Pattern match at index:8 Example 3Output: Exception in thread "main" java.lang.IllegalStateException: No match result available at java.base/java.util.Scanner.match(Scanner.java:1398) at myPackage.ScannerMatchExample3.main(ScannerMatchExample3.java:11) Next TopicJava-scanner-nextbigdecimal-method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India