Java Reference
In-Depth Information
17.1 Introduction
17.2 Functional Programming
Technologies Overview
17.2.1 Functional Interfaces
17.2.2 Lambda Expressions
17.2.3 Streams
17.3 IntStream Operations
17.3.1 Creating an IntStream and
Displaying Its Values with the
forEach Terminal Operation
17.3.2 Terminal Operations count , min ,
max , sum and average
17.3.3 Terminal Operation reduce
17.3.4 Intermediate Operations: Filtering and
Sorting IntStream Values
17.3.5 Intermediate Operation: Mapping
17.3.6 Creating Streams of int s with
IntStream Methods range and
rangeClosed
17.4 Stream<Integer> Manipulations
17.4.1 Creating a Stream<Integer>
17.4.2 Sorting a Stream and Collecting the
Results
17.4.3 Filtering a Stream and Storing the
Results for Later Use
17.4.4 Filtering and Sorting a Stream and
Collecting the Results
17.4.5 Sorting Previously Collected Results
17.5 Stream<String> Manipulations
17.5.1
17.5.2 Filtering String s Then Sorting Them
in Case-Insensitive Ascending Order
17.5.3 Filtering String s Then Sorting Them
in Case-Insensitive Descending Order
17.6 Stream<Employee> Manipulations
17.6.1 Creating and Displaying a
List<Employee>
17.6.2 Filtering Employee s with Salaries in a
Specified Range
17.6.3 Sorting Employee s By Multiple Fields
17.6.4 Mapping Employee s to Unique Last
Name String s
17.6.5 Grouping Employee s By Department
17.6.6 Counting the Number of Employee s
in Each Department
17.6.7 Summing and Averaging Employee
Salaries
17.7 Creating a Stream<String> from a
File
17.8 Generating Streams of Random
Values
17.9 Lambda Event Handlers
17.10 Additional Notes on Java SE 8
Interfaces
17.11 Java SE 8 and Functional
Programming Resources
17.12 Wrap-Up
Mapping String s to Uppercase
Using a Method Reference
Summary | Self-Review Exercises | Answers to Self-Review Exercises | Exercises
17.1 Introduction
The way you think about Java programming is about to change profoundly. Prior to Java
SE 8, Java supported three programming paradigms— procedural programming , object-ori-
ented programming and generic programming . Java SE 8 adds functional programming . The
new language and library capabilities that support this paradigm were added to Java as part
of Project Lambda:
http://openjdk.java.net/projects/lambda
In this chapter, we'll define functional programming and show how to use it to write
programs faster, more concisely and with fewer bugs than programs written with previous
techniques. In Chapter 23, Concurrency, you'll see that functional programs are easier to
parallelize (i.e., perform multiple operations simultaneously) so that your programs can
take advantage of multi-core architectures to enhance performance. Before reading this
chapter, you should review Section 10.10, which introduced Java SE 8's new interface fea-
 
 
Search WWH ::




Custom Search