The Wayback Machine - https://web.archive.org/web/20241001025801/https://www.geeksforgeeks.org/matcher-findint-method-in-java-with-examples/
Open In App

Matcher find(int) method in Java with Examples

Last Updated : 26 Nov, 2018
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

The find(int start) method of Matcher Class attempts to find the next subsequence after the specified subsequence number, passed as parameter, of the input sequence that find the pattern. It returns a boolean value showing the same.

Syntax:

public boolean find(int start)

Parameters: This method takes a parameter start which is the subsequence number after which the next subsequence is to be found.

Return Value: This method returns a boolean value showing whether a subsequence of the input sequence find this matcher’s pattern

Exception: This method throws IndexOutOfBoundsException if start is less than zero or greater than the length of the input sequence.

Below examples illustrate the Matcher.find() method:

Example 1:




// Java code to illustrate find() method
  
import java.util.regex.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Get the regex to be checked
        String regex = "Geeks";
  
        // Create a pattern from regex
        Pattern pattern
            = Pattern.compile(regex);
  
        // Get the String to be matched
        String stringToBeMatched
            = "GeeksForGeeks";
  
        // Create a matcher for the input String
        Matcher matcher
            = pattern
                  .matcher(stringToBeMatched);
  
        // Get the subsequence
        // using find() method
        System.out.println(matcher.find(1));
    }
}


Output:

true

Example 2:




// Java code to illustrate find() method
  
import java.util.regex.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Get the regex to be checked
        String regex = "GFG";
  
        // Create a pattern from regex
        Pattern pattern
            = Pattern.compile(regex);
  
        // Get the String to be matched
        String stringToBeMatched
            = "GFGFGFGFGFGFGFGFGFG";
  
        // Create a matcher for the input String
        Matcher matcher
            = pattern
                  .matcher(stringToBeMatched);
  
        // Get the subsequence
        // using find() method
        System.out.println(matcher.find(0));
    }
}


Output:

true

Reference: Oracle Doc



Similar Reads

TimeZone getOffset(int, int, int, int, int, int) Method in Java with Examples
The getOffset(int era, int yr, int mon, int day, int dayOfWeek, int millisec) method of TimeZone class in Java is used to know the offset value of this TimeZone at a specific date or modified date in case of daylight savings, from the UTC or the Universal Time Coordinated. This offset value can be added to get the local time. Syntax: public abstrac
2 min read
Matcher region(int, int) method in Java with Examples
The region(int, int) method of Matcher Class restricts the region to be matched by the pattern. This region must be lesser than or same as the previous region, but not greater. Else it would lead to IndexOutOfBoundsException. This method returns a Matcher with the new matching region. Syntax: public Matcher region(int startIndex, int endIndex) Para
3 min read
ZoneOffset ofHoursMinutesSeconds(int, int, int) method in Java with Examples
The ofHoursMinutesSeconds(int, int, int) method of ZoneOffset Class in java.time package is used to obtain an instance of ZoneOffset using the offset in hours, minutes and seconds passed as the parameter. This method takes the hours, minutes and seconds as parameter in the form of int and converts it into the ZoneOffset. Syntax: public static ZoneO
2 min read
SimpleTimeZone setStartRule(int, int, int) method in Java with Examples
The setStartRule(int startofMonth, int startofDay, int startofTime) method of SimpleTimeZone class in Java is used to set a particular start rule of the day-light saving time to a fixed date within a given month. Syntax: public void setStartRule(int startofMonth, int startofDay, int startofTime) Parameters: The method takes three parameters: starto
2 min read
SimpleTimeZone setEndRule(int, int, int) method in Java with Examples
The setEndRule(int endofMonth, int endofDay, int endofTime) method of SimpleTimeZone class in Java is used to set a particular rule of the day-light saving time to a fixed date within a given month. Syntax: public void setEndRule(int endofMonth, int endofDay, int endofTime) Parameters: The method takes three parameters: endofMonth: This is of Integ
2 min read
Matcher start(int) method in Java with Examples
The start(int group) method of Matcher Class is used to get the start index of the match result already done, from the specified group. Syntax: public int start(int group) Parameters: This method takes a parameter group which is the group from which the start index of the matched pattern is required. Return Value: This method returns the index of t
2 min read
Matcher end(int) method in Java with Examples
The end(int group) method of Matcher Class is used to get the offset after the end index of the match result already done, from the specified group. Syntax: public int end(int group) Parameters: This method takes a parameter group from which the offset after the end index of the matched pattern is required. Return Value: This method returns the off
2 min read
Matcher group(int) method in Java with Examples
The group(int group) method of Matcher Class is used to get the group index of the match result already done, from the specified group. Syntax: public String group(int group) Parameters: This method takes a parameter group which is the group from which the group index of the matched pattern is required. Return Value: This method returns the index o
2 min read
HijrahDate of(int, int, int) method in Java with Example
The of() method of java.time.chrono.HijrahDate class is used to generate the date according to Islamic hijri calendar system by using the passed proleptic year, month and date. Syntax: public static HijrahDate of(int Year, int month, int dayOfMonth) Parameter: This method takes the following argument as a parameter: year: which is the integer value
2 min read
IsoChronology date(int, int, int) method in Java with Example
The date() method of java.time.chrono.IsoChronology class is used get the local date according to ISO calendar system for the given year, month and day. Syntax: public LocalDate date(int prolepticYear, int month, int dayOfMonth) Parameter: This method takes the following arguments as parameter. prolepticYear: integer proleptic year for the year fie
2 min read
JapaneseChronology date(int, int, int) method in Java with Example
The date() method of java.time.chrono.JapaneseChronology class is used get the local date according to japanese calendar system for the given year, month and day.Syntax: public JapaneseDate date(int prolepticYear, int month, int dayOfMonth) Parameter: This method takes the following arguments as parameter. prolepticYear: integer proleptic year for
2 min read
JapaneseDate of(int, int, int) method in Java with Example
The of() method of java.time.chrono.JapaneseDate class is used to generate the date according to japanese calendar system by using the passed proleptic year, month and date. Syntax: public static JapaneseDate of(int prolepticYear, int month, int dayOfMonth) Parameter: This method takes the following argument as a parameter: year: which is the integ
2 min read
JapaneseDate of(JapaneseEra,int, int, int) method in Java with Example
The of() method of java.time.chrono.JapaneseDate class is used to generate the date according to Japanese calendar system by using the passed proleptic year, month, date and JapaneseEra. Syntax: public static JapaneseDate of(JapaneseEra era, int yearOfEra, int month, int dayOfMonth) Parameter: This method takes the following argument as a parameter
2 min read
MinguoChronology date(int, int, int) method in Java with Example
The date() method of java.time.chrono.MinguoChronology class is used get the local date according to Minguo calendar system for the given year, month and day.Syntax: public MinguoDate date(int prolepticYear, int month, int dayOfMonth) Parameter: This method takes the following arguments as parameter. prolepticYear: integer proleptic year for the ye
2 min read
MinguoDate of(int, int, int) method in Java with Example
The of() method of java.time.chrono.MinguoDate class is used to generate the date according to Minguo calendar system by using the passed proleptic year, month and date. Syntax: public static MinguoDate of(int Year, int month, int dayOfMonth) Parameter: This method takes the following argument as a parameter: year: which is the integer value of yea
2 min read
ThaiBuddhistChronology date(int, int, int) method in Java
The date() method of java.time.chrono.ThaiBuddhistChronology class is used get the local date according to ThaiBuddhist calendar system for the given year, month and day.Syntax: public ThaiBuddhistDate date(int prolepticYear, int month, int dayOfMonth) Parameter: This method takes the following arguments as parameter. prolepticYear: integer prolept
2 min read
Matcher find() method in Java with Examples
The find() method of Matcher Class attempts to find the next subsequence of the input sequence that find the pattern. It returns a boolean value showing the same. Syntax: public boolean find() Parameters: This method do not takes any parameter. Return Value: This method returns a boolean value showing whether a subsequence of the input sequence fin
2 min read
Java Guava | IntMath.checkedSubtract(int a, int b) method with Examples
The checkedSubtract(int a, int b) is a method of Guava's IntMath Class which accepts two parameters a and b, and returns their difference. Syntax: public static int checkedSubtract(int a, int b) Parameters: The method accepts two int values a and b and computes their difference. Return Value: The method returns the difference of int values passed t
2 min read
Java Guava | IntMath.checkedMultiply(int a, int b) method with Examples
The checkedMultiply(int a, int b) is a method of Guava's IntMath Class which accepts two parameters a and b, and returns their product. Syntax: public static int checkedMultiply(int a, int b) Parameters: The method accepts two int values a and b and computes their product. Return Value: The method returns the product of int values passed to it, pro
2 min read
ZoneOffset ofHoursMinutes(int, int) method in Java with Examples
The ofHoursMinutes(int, int) method of ZoneOffset Class in java.time package is used to obtain an instance of ZoneOffset using the offset in hours and minutes passed as the parameter. This method takes the hours and minutes as parameter in the form of int and converts it into the ZoneOffset. Syntax: public static ZoneOffset ofHoursMinutes(int hours
2 min read
PrintWriter write(String, int, int) method in Java with Examples
The write(String, int, int) method of PrintWriter Class in Java is used to write a specified portion of the specified String on the stream. This String is taken as a parameter. The starting index and length of String to be written are also taken as parameters. Syntax: public void write(String string, int startingIndex, int lengthOfstring) Parameter
2 min read
PrintWriter write(char[], int, int) method in Java with Examples
The write(char[], int, int) method of PrintWriter Class in Java is used to write a specified portion of the specified character array on the stream. This character array is taken as a parameter. The starting index and length of characters to be written are also taken as parameters. Syntax: public void write(char[] charArray, int startingIndex, int
2 min read
PrintWriter append(CharSequence, int, int) method in Java with Examples
The append(CharSequence, int, int) method of PrintWriter Class in Java is used to append a specified portion of the specified charSequence on the stream. This charSequence is taken as a parameter. The starting index and ending index to be written are also taken as parameters. Syntax: public void append(CharSequence charSequence, int startingIndex,
2 min read
PrintStream append(CharSequence, int, int) method in Java with Examples
The append(CharSequence, int, int) method of PrintStream Class in Java is used to append a specified portion of the specified charSequence on the stream. This charSequence is taken as a parameter. The starting index and ending index to be written are also taken as parameters. Syntax: public void append(CharSequence charSequence, int startingIndex,
2 min read
PrintStream write(byte[], int, int) method in Java with Examples
The write(byte[], int, int) method of PrintStream Class in Java is used to write a specified portion of the specified byteacter array on the stream. This byteacter array is taken as a parameter. The starting index and length of byteacters to be written are also taken as parameters. Syntax: public void write(byte[] byteArray, int startingIndex, int
2 min read
Writer append(CharSequence, int, int) method in Java with Examples
The append(CharSequence, int, int) method of Writer Class in Java is used to append a specified portion of the specified charSequence on the writer. This charSequence is taken as a parameter. The starting index and ending index to be written are also taken as parameters. Syntax: public void append(CharSequence charSequence, int startingIndex, int e
2 min read
StringWriter write(char[], int, int) method in Java with Examples
The write(char[], int, int) method of StringWriter Class in Java is used to write a specified portion of the specified character array on the writer. This character array is taken as a parameter. The starting index and length of characters to be written are also taken as parameters. Syntax: public void write(char[] charArray, int startingIndex, int
2 min read
StringWriter write(String, int, int) method in Java with Examples
The write(String, int, int) method of StringWriter Class in Java is used to write a specified portion of the specified String on the stream. This String is taken as a parameter. The starting index and length of String to be written are also taken as parameters. Syntax: public void write(String string, int startingIndex, int lengthOfstring) Paramete
2 min read
StringWriter append(CharSequence, int, int) method in Java with Examples
The append(CharSequence, int, int) method of StringWriter Class in Java is used to append a specified portion of the specified charSequence on the writer. This charSequence is taken as a parameter. The starting index and ending index to be written are also taken as parameters. Syntax: public void append(CharSequence charSequence, int startingIndex,
2 min read
Java Guava | LongMath.checkedMultiply(int a, int b) method with Examples
The checkedMultiply(long a, long b) is a method of Guava's LongMath Class which accepts two parameters a and b, and returns their product. Syntax: public static long checkedMultiply(long a, long b) Parameters: The method accepts two long values a and b and computes their product. Return Value: The method returns the product of long values passed to
2 min read
Practice Tags :