Java程序检查列表中的所有字符串是否都不符合条件
首先,使用String元素创建一个List:
List<String> myList = new ArrayList<>();
myList.add("pqr");
myList.add("stu");
myList.add("vwx");
myList.add("yza");
myList.add("bcd");
myList.add("efg");
myList.add("vwxy");使用该noneMatch()方法检查myList中的上述字符串是否都不以特定字母开头:
myList.stream().noneMatch((a) -> a.startsWith("f"));如果所有字符串都不以特定字母开头,则返回TRUE,否则返回FALSE。
以下是检查列表中的所有字符串是否不符合条件的示例:
示例
import java.util.ArrayList;
import java.util.List;
public class Demo {
public static void main(final String[] args) {
List<String> myList = new ArrayList<>();
myList.add("pqr");
myList.add("stu");
myList.add("vwx");
myList.add("yza");
myList.add("bcd");
myList.add("efg");
myList.add("vwxy");
boolean res = myList.stream().noneMatch((a) -> a.startsWith("f"));
System.out.println("No match for the starting letter as f? = "+res);
}
}输出结果
No match for the starting letter as f? = true
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短