//CountingEmptyStrings.java

import java.util.Arrays;
import java.util.List;

public class CountingEmptyStrings
{
    public static void main(String args[])
    {
        //We will count the empty strings in the following list of strings:
        List<String> strings
            = Arrays.asList("abc", "", "bc", "efg", "abcd", "", "jkl", "mno");
        System.out.println("\nList of strings: " + strings);

        System.out.println("\n=============");
        System.out.println("Using Java 7: ");
        int count = 0;
        for (String string : strings)
        {
            if (string.isEmpty())
            {
                count++;
            }
        }
        System.out.println("Number of empty strings: " + count);

        System.out.println("\n=============");
        System.out.println("Using Java 8: ");
        System.out.println
        (
            "Number of empty strings: " + strings
            .stream()
            .filter(string -> string.isEmpty())
            .count()
        );
    }
}
/*  Output:

    List of strings: [abc, , bc, efg, abcd, , jkl, mno]

    =============
    Using Java 7:
    Number of empty strings: 2

    =============
    Using Java 8:
    Number of empty strings: 2
*/
