0 votes
in Education by (55.6k points)

How will you print count of empty strings in Java 8?

1 Answer

0 votes
by (55.6k points)

How will you print count of empty strings in Java 8?

The following code segment prints a count of empty strings using filter.

List<String>strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");

//get count of empty string

int count = strings.stream().filter(string -> string.isEmpty()).count();

...