Home  >  Article  >  Java  >  Match matching method in java

Match matching method in java

WBOY
WBOYforward
2023-04-28 22:31:062372browse

Explanation

match is used for matching operations, and its return value is of boolean type. Through match, you can simply verify whether a certain element exists in the list.

Example

// 验证 list 中 string 是否有以 a 开头的, 匹配到第一个,即返回 true
boolean anyStartsWithA =
    stringCollection
        .stream()
        .anyMatch((s) -> s.startsWith("a"));
 
System.out.println(anyStartsWithA);      // true
 
// 验证 list 中 string 是否都是以 a 开头的
boolean allStartsWithA =
    stringCollection
        .stream()
        .allMatch((s) -> s.startsWith("a"));
 
System.out.println(allStartsWithA);      // false
 
// 验证 list 中 string 是否都不是以 z 开头的,
boolean noneStartsWithZ =
    stringCollection
        .stream()
        .noneMatch((s) -> s.startsWith("z"));
 
System.out.println(noneStartsWithZ);      // true

What are the basic data types of java

The basic data types of Java are divided into:

1. Integer type , a data type used to represent integers.

2. Floating point type, a data type used to represent decimals.

3. Character type. The keyword of character type is "char".

4. Boolean type is the basic data type that represents logical values.

The above is the detailed content of Match matching method in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete