Java Scanner findInLine(String pattern) method example

HQ » Java Tutorial » java.util » Scanner » findInLine(String pattern) method example
Java Scanner findInLine(String pattern) method example 2018-02-20T12:07:02+00:00

java.util.Scanner findInLine(String pattern)

Description :

This java tutorial shows how to use the findInLine(String pattern) method of Scanner class of java.util package. This method returns a String object that satisfies the pattern specified as method argument.

Method Syntax :

public String findInLine(String pattern)

Parameter Input :

DataType Parameter Description
N/A N/A This method argument tells the Scanner on which Pattern object to search

Method Returns :

This method simply returns the string that satisfies the pattern specified on the method argument.

Compatibility Version :

Requires Java 1.5 and up

Exception :

IllegalStateException

– The IllegalStateException will be thrown by findInLine method of Scanner class if the invocation is done after the scanner has been closed.

Discussion :

The Scanner findInLine(String pattern) method is used to search for a pattern on the scanner buffer regardless of delimiters. This is the same as calling the method findInLine(Pattern.compile(pattern)).

Java Code Example :

This java example source code demonstrates the use of findInLine method of Scanner class. Basically this codes make use of hasNextLine() and nextLine() to move through the contents of the file line by line. And by using the findInLine() method, we have used used it to get only the contents which satisfies the pattern that we have specified.

File Contents:

Sample Output :

Running the findInLine(String pattern) method example source code of Scanner class will give you the following output

java scanner findinline string pattern method example

java scanner findinline string pattern method example

Exception Scenario :

Similar Method :

  • N/A

Suggested Reading List :

References :

 

Contact Info

Singapore

Our Goal

JavaTutorialHQ aims to to be The Ultimate Guide on Java with hundreds of examples from basic to advance Topics.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close