The match() method of java.util.Scanner class returns the match result of the last scanning operation performed by this scanner.
public MatchResult match()
Return Value: This function returns a match result for the last match operation.
Exceptions: The function throws IllegalStateException if no match has been performed, or if the last match was not successful.
Below programs illustrate the above function:
true java.util.regex.Matcher[pattern=GFG region=0, 10 lastmatch=GFG] GFG Geeks!
Program 2: To demonstrate IllegalStateException
false Exception caught is: java.lang.IllegalStateException: No match result available
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.