Java Scanner findInLine() MethodThe findInLine() is a Java Scanner class method which is used to find the next occurance of a pattern. There is two different types of Java findInLine() method which can be differentiated depending on its parameter. These are:
findInLine(String pattern) Method:This is a Java Scanner class method which is used to find the next occurrence of a pattern constructed from the specified string, ignoring delimiters. findInLine(Pattern pattern) Method:This is an inbuilt method of Java Scanner class which is used to find the next occurrence of the specified pattern ignoring delimiters. SyntaxFollowing is the declaration of findInLine() method: Parameter
ReturnsThe findInLine() method returns the text that matched the specified pattern. ExceptionsIllegalStateException- This method throws exception if the innvocation is done after the scanner has been closed. Compatibility VersionJava 1.5 and above Example 1Output: Output: World Left String: ! Example 2Output: Exception in thread "main" java.lang.IllegalStateException: Scanner closed at java.base/java.util.Scanner.ensureOpen(Scanner.java:1150) at java.base/java.util.Scanner.findInLine(Scanner.java:1699) at java.base/java.util.Scanner.findInLine(Scanner.java:1677) at myPackage.ScannerFindInLineExample2.main(ScannerFindInLineExample2.java:10) Example 3Output: Output: Hello Left String: World! Hello India! Example 4Output: Enter your email address: [email protected] Output:rahul Next TopicJava-scanner-findwithinhorizon-method |