List<String> list;
//...add something in the list
String value = "anything";
boolean b = list.stream().anyMatch( element -> value.startsWith(element))
我通过方法参考获取有关用lambda替换的声纳信息。但是我必须在String上调用方法引用???
答案 0 :(得分:7)
String value = "anything";
boolean b = list.stream().anyMatch( value::startsWith);
或者你甚至不需要声明String value
,你可以使用&#34;任何东西&#34;直接在lambda表达式中:
list.stream().anyMatch( "anything"::startsWith)