Lambda expressions exercises and practice While lambda expressions in java 8 are really cool in action, the school curriculum offers no exercises in this. So essentially, students never actually learn how to use lambda expressions and the java 8 functional interfaces that go with it when teaching in java (i.e. Stream, Predicate etc.)

There are a few periods for labs and practice which can be devoted for lambda expressions, but I am not sure what kind of labs I can make, which are focused on lambda expressions (not only utilizing them).

What I did think of is asking them to perform a number of tasks:


given a List of String and some condition (not coded as a Predicate, yet...), return a List of all strings that meet the condition. This exercise is meant as a starter. Just to get them going.
Here the fun starts Streaming. They are given a list of objects (which I wrote) that each have a String and an Integer. They need to return a list of the integers from those objects. 


The problem is that those two are very short, and are introductory. I am trying to think of other exercises or tasks which are almost entirely with lambda expressions. 

Which kind of exercises could I give the students that would both show them just how cool lambda expressions and the functional API are, but also give them plenty of hands-on experience with what Java's functional API has to offer?

(PS, the students are high school students)
One of the interesting things added to java in v8 is functional interfaces. Previously java only matched things up and verified correctness by type (type names). With functional interfaces, java now looks at the structure of code in certain situations. 

I can add examples to this answer to clarify if anyone asks. 

One interesting feature you can add is a method to do simple repetition. I like to teach a lot of things before if and while, but sometimes you just need repetition and the most common sort is a constant-number-of-iterations loop. 

@FunctionalInterface
public interface LocalCommand  
{    
    public void accept();

}

/**
 *  Repeat a method a given number of times
 * @param howMany number of times to repeat the method
 * @param what the method itself, as a Command. Especially useful in Java 8
*/
public static void repeat(int howMany, LocalCommand what){
    for (int i = 0; i &lt; howMany; ++i){
        what.accept();
    } 
}


Usage:

public void aCommand(){
    // do something interesting
}

repeat(3, aCommand()); // structural matching with the functional interface
repeat(3, () -&gt; {aCommand();}); //lambda expression   
repeat(3, () -&gt; {System.out.println("Hello");}); //lambda expression


In java 8 you don't need to ever explicitly say that aCommand is, in fact, aCommand and you don't need a new enclosing type to implement the functional interface. You don't even need to specifically say that it is a functional interface, Java will grok it by structure alone. 

With repeat(...) in my library I can do repetition before I need to talk about for and while loops.



I used only the simplest case of a functional interface here. You can use Consumers, etc just as well with only a bit more complexity.