Problems

Use the following problems to test your functional style programming prowess. I strongly encourage you to give each problem a try before you turn to the solutions and download the example programs:

  1. Testing high-order functions: Write several unit tests for testing so-called high-order functions.
  2. Testing methods that use lambdas: Write several unit tests for testing methods that use lambdas.
  3. Debugging lambdas: Provide a technique for debugging lambdas.
  4. Filtering the non-zero elements of a stream: Write a stream pipeline that filters the non-zero elements of a stream.
  5. Infinite streams, takeWhile(), and dropWhile(): Write several snippets of code that work with infinite streams. In addition, write several examples of working with the takeWhile() and dropWhile() APIs.
  6. Mapping a stream: Write several examples of mapping a stream via map() and flatMap().
  7. Finding different elements in a stream: Write a program for finding different elements in a stream.
  8. Matching different elements in a stream: Write a program for matching different elements in a stream.
  9. Sum, max, and min in a stream: Write a program for computing the sum, max, and min of the given stream via primitive specializations of Stream and Stream.reduce().
  10. Collecting the results of a stream: Write several snippets of code for collecting the results of a stream in a list, map, and set.
  11. Joining the results of a stream: Write several snippets of code for joining the results of a stream into a String.
  12. Summarization collectors: Write several snippets of code to reveal the usage of summarization collectors.
  13. Grouping: Write snippets of code for working with groupingBy() collectors.
  14. Partitioning: Write several snippets of code for working with partitioningBy() collectors.
  15. Filtering, flattening, and mapping collectors: Write several snippets of code for exemplifying the usage of filtering, flattening, and mapping collectors.
  16. Teeing: Write several examples that merge the results of two collectors (JDK 12 and Collectors.teeing()).
  17. Writing a custom collector: Write a program that represents a custom collector.
  18. Method reference: Write an example of method reference.
  19. Parallel processing of streams: Provide a brief overview of the parallel processing of streams. Provide at least one example each for parallelStream(), parallel(), and spliterator().
  20. Null-safe streams: Write a program that returns a null-safe stream from an element or a collection of elements.
  21. Composing functions, predicates, and comparators: Write several examples for composing functions, predicates, and comparators.
  22. Default methods: Write an interface that contains a default method.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.216.175