美文网首页
Java stream 如何优雅地反向 filter

Java stream 如何优雅地反向 filter

作者: 风神AI | 来源:发表于2018-02-11 14:02 被阅读0次

    How to negate a method reference predicate

    https://stackoverflow.com/questions/21488056/how-to-negate-a-method-reference-predicate

    public static <T> Predicate<T> not(Predicate<T> t) {
        return t.negate();
    }
    
    Stream<String> s = ...;
    long nonEmptyStrings = s.filter(not(String::isEmpty)).count();
    

    相关文章

      网友评论

          本文标题:Java stream 如何优雅地反向 filter

          本文链接:https://www.haomeiwen.com/subject/fsiktftx.html