Hi There!

I'm Dan Schlegel, an Assistant Professor in the Computer Science Department at SUNY Oswego

Lab 7 – Lambdas and Streams

In this lab you will convert some code from normal iterative pre-java-8 Java to code using lambdas and streams. Before you begin, review the Java tutorials on Lambdas and Streams.

Begin by placing the following code into a file called Person.java in a new Gradle project.

1. Write the enhanced for statement in the printMaleNames method as a stream pipeline with lambda expressions. Hint: Use the filter intermediate operation and the forEach terminal operation.

2. Convert code in printUniqueFemaleNamesByLength into a new implementation that uses lambda expressions and aggregate operations instead of multiple for loops. Hint: Make a pipeline that invokes the filter, map, distinct, sorted, and forEach operations, in that order.

Once you’ve finished the lab, show it to the TA so that she can mark you as having completed it.