Home  >  Article  >  Java  >  What does java Predicate refer to?

What does java Predicate refer to?

王林
王林forward
2023-05-01 20:49:141131browse

Explanation

Predicate is a function interface that specifies the participating type and returns a boolean value. Default implementation methods are provided internally, which can combine complex logical judgments (and, or, negate).

Example

import java.util.function.Predicate;
 
/**
 * 我们来验证一下,那说的比较矛盾的地方。
 * 1. 评估参数里面的表达式(说白了就是验证传进来的参数符不符合规则,后面有例子)
 *    我们来验证一下这句话,并且解释一下。
 */
public class PredicateTestOne {
 
    public static void main(String[] args) {
 
        PredicateTestOne predicateTestOne = new PredicateTestOne();
 
        Predicate<String> predicate = new Predicate<String>() {
            @Override
            public boolean test(String s) {
 
                return s.equals("zhangsan");
            }
        };
 
        System.out.println(predicate.test("lisi"));
        System.out.println("--- --- --- --- --- ---");
        System.out.println(predicate.test("zhangsan"));
    }
}

The above is the detailed content of What does java Predicate refer to?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete