Java Scanner findWithinHorizon() method example

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

java.util.Scanner findWithinHorizon()

Description :

This java tutorial shows how to use the findWithinHorizon method of Scanner class of java.util package. This method returns a String that corresponds to the pattern specified as method argument. This method simply attempts to find the next occurrence of a pattern input ignoring delimiters.

Method Syntax :

There are two overloaded method of Scanner findWithinHorizon java method.

java scanner findwithinhorizon overloaded method
Note:
Overloaded methods are those method with same name but with different method signatures


Method 1 : 

public String findWithinHorizon(String pattern,int horizon)

Method 2:

public String findWithinHorizon(Pattern pattern,int horizon)

Parameter Input :

DataType Parameter Description
String Pattern a string specifying the pattern to search for
Pattern Pattern The pattern to search for by this Scanner
int horizon

Method Returns :

This method returns the String which satisfies the  pattern specified as method argument within the horizon. If the pattern was found, the Scanner object skipped the string that satisfies the pattern specified and returns the string that matched the pattern. If the pattern was not found, the scanner will return null and the position will not changed.

Compatibility Version :

Requires Java 1.5 and up

Exception :

None

Discussion :

Basically the two overloaded findWithinHorizon method do the same tasks. Mean to say that invoking findWithinHorizon(String pattern,int horizon) is the same as findWithinHorizon(Pattern.compile(String pattern),int horizon).

The horizon method argument signifies how many characters have to be taken out to satisfy the pattern specified.

Java Code Example :

This java example source code demonstrates the use of findWithinHorizon method of Scanner class.

Sample Output :

Running the findWithinHorizon method example source code of Scanner class will give you the following output

Exception Scenario :

N/A

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