import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;


public class JavaAdvDataStreams01 {

  public static void main(String[] args) {

    final List<String> femaleNamesList = Arrays.asList(
        "Amy", "Debbie", "Jane", "Justine"
    );

    String[] myArray = new String[] {
        "FRED", "debbie", "AMY", "JanE", null, null, null, "Theodore",
        "Leonard", "Ralph", "JustiNE", "Samuel",
        "George", "Albert"
    };

    // Create a sample Data Stream a String array
    Stream<String> mapStream = Arrays.stream(myArray);

    String newString = mapStream
            .filter(e -> e != null)
            .map(s -> {String lowerCaseStr = s.toLowerCase();
              return Character.toUpperCase(lowerCaseStr.charAt(0)) +
                      lowerCaseStr.substring(1);})
            .collect(Collectors.toList()).toString();
    System.out.println("newString = " + newString);

    mapStream = Arrays.stream(myArray);
    // Example of map, filter, then reduce
    newString = mapStream
            .filter(s -> s != null)
            .map(s -> {
              String lowerCaseStr = s.toLowerCase();
              return Character.toUpperCase(lowerCaseStr.charAt(0)) +
                      lowerCaseStr.substring(1);
            })
            .filter(femaleNamesList::contains)
            .reduce("Search results:", (accumulator, mapValue) -> {
              if (accumulator.endsWith(":")) {
                return accumulator + " " + mapValue;
              } else {
                return accumulator + ", " + mapValue;
              }
            });

    // List all newly mapped elements
    System.out.println(newString);

    // Show result of convenient map count()
    System.out.println("Number of female names found = " +
        newString.split(", ").length);

  }
}

@@ -41,16 +41,43 @@
 l.List;%0A
+import java.util.Optional;%0A
 import j
@@ -625,24 +625,26 @@
 rray);%0A%0A    
+  
 String newSt
@@ -676,79 +676,78 @@
     
-.filter(e -%3E e != null)%0A            .map(s -%3E %7BString lowerCaseStr = s.
+  .map(s -%3E Optional.ofNullable(s)%0A                      .map(String::
 toLo
@@ -745,36 +745,37 @@
 ing::toLowerCase
-();%0A
+)%0A   
               re
@@ -764,38 +764,57 @@
                 
-return
+     .map(lowerCaseStr -%3E
  Character.toUpp
@@ -860,32 +860,40 @@
                 
+        
 lowerCaseStr.sub
@@ -905,12 +905,54 @@
 g(1)
-;%7D
 )%0A
+                      .orElse(%22UNKNOWN%22))%0A  
     

Update to use Optional.ofNullable() for null checking.