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
ofString
and some condition (not coded as aPredicate
, yet...), return aList
of all strings that meet the condition. This exercise is meant as a starter. Just to get them going. - Here the fun starts
Stream
ing. 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)