以下是一个用 Java 的 Stream API 对 HashSet 进行过滤和计数的示例代码:HashSet<Object> set = new HashSet<>(); // 向 set 中添加元素 long count = set.stream() .filter(e -> e.getProperty().equals("value")) .count(); 这段代码使用了 Java 8 中的 Stream API。它首先将 HashSet 转换为一个 Stream,然后使用 filter