A predicate is often used in mathematics that something that takes a value for an argument and then returns true or false. In the examples below we will show common uses of java.util.function.Predicate.
Setup
Predicate test
The 'test' method evalues the predicate on the given argument. In this example, we test the string to verify it has a length of 10.
Predicate and
The predicate 'and' method returns a composed predicate that represents a short-circuiting logical AND of this predicate and another. Ihe code below we will validate that the string is not null and it has length of greater than 10.
Predicate negate
The predicate 'negate' method returns a predicate that represents the logical negation or opposite. In the case below, the string has a length of 10 but since we call the negate it will return false.
Predicate or
The predicate 'or' method returns a composed predicate that represents a short-circuiting logical OR of this predicate and another. We create an additional predicate that checks to see if the string contains the letter "A" and then also check if string has the length of 10.