Pattern asPredicate() Method in Java with Examples Last Updated : 12 Apr, 2023 Comments Improve Suggest changes Like Article Like Report asPredicate() method of a Pattern class used to creates a predicate object which can be used to match a string.Predicate is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. Syntax: public Predicate asPredicate() Parameters: This method accepts nothing as parameter. Return value: This method returns a predicate which can be used for matching on a string. Below programs illustrate the asPredicate() method: Program 1: Java // Java program to demonstrate // Pattern.asPredicate() method import java.util.regex.*; import java.util.function.*; public class GFG { public static void main(String[] args) { // create a REGEX String String REGEX = "ee"; // create the string // in which you want to search String actualString = "aaeebbeecceeddee"; // create a Pattern using REGEX Pattern pattern = Pattern.compile(REGEX); // get Predicate Object Predicate<String> predicate = pattern.asPredicate(); // check whether predicate match // with actualString boolean value = predicate .test(actualString); // print result System.out.println("value matched: " + value); } } Output:value matched: true Program 2: Java // Java program to demonstrate // Pattern.asPredicate() method import java.util.regex.*; import java.util.function.*; public class GFG { public static void main(String[] args) { // create a REGEX String String REGEX = "org"; // create the string // in which you want to search String actualString = "welcome geeks"; // create a Pattern using REGEX Pattern pattern = Pattern.compile(REGEX); // get Predicate Object Predicate<String> predicate = pattern.asPredicate(); // check whether predicate match // with actualString boolean value = predicate.test(actualString); // print result System.out.println("value matched: " + value); } } Output:value matched: false Reference: https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html#asPredicate() Comment More infoAdvertise with us Next Article Pattern asPredicate() Method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions java-regular-expression Java-Pattern +1 More Practice Tags : Java Similar Reads Pattern split(CharSequence) method in Java with Examples split(CharSequence) method of a Pattern class used to splits the given char sequence passed as parameter to method around matches of this pattern.This method can split charSequence into an array of String's, using the regular expression used to compile the pattern as a delimiter.so we can say that t 2 min read Pattern compile(String) method in Java with Examples The compile(String) method of the Pattern class in Java is used to create a pattern from the regular expression passed as parameter to method. Whenever you need to match a text against a regular expression pattern more than one time, create a Pattern instance using the Pattern.compile() method.Synta 2 min read Pattern flags() method in Java with Examples The flags() method of the Pattern class in Java is used to return the pattern's match flags. The Match flags are a bit mask that may include CASE_INSENSITIVE, MULTILINE, DOTALL, UNICODE_CASE, CANON_EQ, UNIX_LINES, LITERAL, UNICODE_CHARACTER_CLASS and COMMENTS Flags. Syntax: public int flags() Parame 2 min read Pattern matcher(CharSequence) method in Java with Examples The matcher(CharSequence) method of the Pattern class used to generate a matcher that will helpful to match the given input as parameter to method against this pattern. The Pattern.matcher() method is very helpful when we need to check a pattern against a text a single time, and the default settings 2 min read Pattern split(CharSequence,int) method in Java with Examples split(CharSequence, int) method of a Pattern class used to splits the given char sequence passed as parameter to method around matches of this pattern.The array returned contains each substring of the input sequence created by this method. The substrings in the array are in the order in which they o 3 min read Like