使用Set< String>创建自定义谓词和String作为参数 [英] Create custom Predicate with Set<String> and String as parameter

查看:201
本文介绍了使用Set< String>创建自定义谓词和String作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串作为ishant和一个 Set< String> 作为[Ishant, Gaurav,sdnj]。我需要为此编写谓词。我尝试过如下代码,但它无法正常工作

I have a String as "ishant" and a Set<String> as ["Ishant", "Gaurav", "sdnj"] . I need to write the Predicate for this. I have tried as below code, but it is not working

Predicate<Set<String>,String> checkIfCurrencyPresent = (currencyList,currency) -> currencyList.contains(currency);

如何创建谓词设置< String> 字符串作为参数并可以给出结果?

How can I create a Predicate which will take Set<String> and String as a parameter and can give the result?

推荐答案

谓词< T> 表示一个参数的谓词(布尔值函数) / strong>。

A Predicate<T> which you're currently using represents a predicate (boolean-valued function) of one argument.

您正在寻找 BiPredicate< T,U> 本质上代表一个谓词(布尔值函数)两个参数

BiPredicate<Set<String>,String>  checkIfCurrencyPresent = (set,currency) -> set.contains(currency);

或方法参考:

BiPredicate<Set<String>,String> checkIfCurrencyPresent = Set::contains;

这篇关于使用Set&lt; String&gt;创建自定义谓词和String作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆