Using java 8 we will calculate the number of upper case letters. Starting with a String we will call chars() which will return a IntStream. From there we will filter out any upper case letters by passing a java 8 predicate Character::isUpperCase. Finally we will use the stream terminal operation count to find the total number of instances.
Google Guava
This snippet will use guava to determine the total number of upper case letters in a String. You can think of CharMatcher as a set of characters so when we use CharMatcher.JAVAUPPERCASE it means any upper case letters. The retainFrom function will remove all non-matching characters or all non upper case values.