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

What does java Predicate refer to?

王林
Release: 2023-05-01 20:49:14
forward
1207 people have browsed it

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"));
    }
}
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template