可以使用Java 8的Stream API来判断集合内字符是否为空。
例如,假设我们有一个List<String>类型的集合,可以使用以下代码来判断集合中的所有字符串是否为空:
List<String> list = Arrays.asList("hello", "", "world", "");
boolean allEmpty = list.stream().allMatch(String::isEmpty);
if (allEmpty) {
System.out.println("All strings are empty");
} else {
System.out.println("Some strings are not empty");
}
在上面的代码中,我们使用stream()
函数将集合转换为一个Stream,然后使用allMatch()
函数来判断所有字符串是否为空,如果所有字符串都为空,则allMatch()
函数返回true,否则返回false。