introducing-java-8.pdf

(1541 KB) Pobierz
Introducing
Java 8
A Quick-Start Guide to Lambdas
and Streams
Raoul-Gabriel Urma
Additional
Resources
4 Easy Ways to Learn More and Stay Current
Programming Newsletter
Get programming related news and content delivered weekly to your inbox.
oreilly.com/programming/newsletter
Free Webcast Series
Learn about popular programming topics from experts live, online.
webcasts.oreilly.com
O’Reilly Radar
Read more insight and analysis about emerging technologies.
radar.oreilly.com
Conferences
Immerse yourself in learning at an upcoming O’Reilly conference.
conferences.oreilly.com
©2015 O’Reilly Media, Inc. The O’Reilly logo is a registered trademark of O’Reilly Media, Inc. #15305
Introducing Java 8
Raoul-Gabriel Urma
Introducing Java 8
by Raoul-Gabriel Urma
Copyright © 2015 O’Reilly Media, Inc. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA
95472.
O’Reilly books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://safaribooksonline.com). For
more information, contact our corporate/institutional sales department:
800-998-9938 or
corporate@oreilly.com.
Editors:
Nan Barber and Brian Foster
Production Editor:
Colleen Lobner
Copyeditor:
Lindsy Gamble
August 2015:
First Edition
Interior Designer:
David Futato
Cover Designer:
Ellie Volckhausen
Illustrator:
Rebecca Demarest
Revision History for the First Edition
2015-08-20:
2015-09-02:
First Release
Second Release
Cover photo: Tiger_2898 by Ken_from_MD via flickr, flipped and converted to
grayscale.
http://www.flickr.com/photos/4675041963_97cd139e83_o.jpg.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
Introducing Java 8
and related trade dress are trademarks of O’Reilly Media, Inc.
While the publisher and the author have used good faith efforts to ensure that the
information and instructions contained in this work are accurate, the publisher and
the author disclaim all responsibility for errors or omissions, including without limi‐
tation responsibility for damages resulting from the use of or reliance on this work.
Use of the information and instructions contained in this work is at your own risk. If
any code samples or other technology this work contains or describes is subject to
open source licenses or the intellectual property rights of others, it is your responsi‐
bility to ensure that your use thereof complies with such licenses and/or rights.
978-1-491-93434-0
[LSI]
Table of Contents
1. Java 8: Why Should You Care?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Code Readability
Multicore
A Quick Tour of Java 8 Features
1
3
3
2. Adopting Lambda Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Why Lambda Expressions?
Lambda Expressions Defined
Lambda Expression Syntax
Where to Use Lambda Expressions
Method References
Putting It All Together
Testing with Lambda Expressions
Summary
The Need for Streams
What Is a Stream?
Stream Operations
Filtering
Matching
Finding
Mapping
Reducing
Collectors
Putting It All Together
Parallel Streams
Summary
11
13
13
14
15
16
18
18
19
20
21
21
22
22
23
23
24
24
26
27
3. Adopting Streams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
v
Zgłoś jeśli naruszono regulamin