SlideShare uma empresa Scribd logo
1 de 29
Introduction to
Java 8 Stream
API
Sidlyarevich Vladislav
Contacts/samples
● https://github.com/kuksenko/jdk8-lambda-samples
● https://github.com/vlsidlyarevich/Stream-API-Examples
● https://www.youtube.com/watch?v=O8oN4KSZEXE
● https://www.youtube.com/watch?v=i0Jr2l3jrDA
Java 8 language features
● Lambdas and Functional Interfaces
● Interface’s Default and Static Methods
● Method References
● Repeating annotations
Java 8 language features
● Date/Time API (JSR 310)
● Nashorn JavaScript engine
● Base64
● Parallel Arrays
● Concurrency
Java 8 language features
STREAM API!
Set<Person> freshBlood = new HashSet<>();
for (Person person : team) {
if (person.age <= 25) {
freshBlood.add(person);
}
}
List<Person> sortedFreshBlood = new ArrayList<>(freshBlood);
Collections.sort(sortedFreshBlood, new Comparator<Person>() {
@Override
public int compare(Person o1, Person o2) {
return Integer.compare(o1.age, o2.age);
}
});
for (Person person : sortedFreshBlood) {
System.out.println(person.name);
}
team.stream()
.filter(person -> person.age <= 25)
.collect(Collectors.toSet())
.stream()
.sorted(comparing(person -> person.age))
.forEach(person -> System.out.println(person.name));
source op op op
terminate
Profit
sources: collections, iterators, api’s
operations: filter, map, reduce, etc
sinks: collections, locals
What is Stream?
Multiplicity of values
Lazy
Single use
Not mutate the source
Ordered/Unordered
Parallel/Sequential
IntStream, DoubleStream, LongStream
What is Stream?
Sequence of elements − A stream provides a set of elements of specific type in a sequential
manner. A stream gets/computes elements on demand. It never stores the elements.
Source − Stream takes Collections, Arrays, or I/O resources as input source.
Aggregate operations − Stream supports aggregate operations like filter, map, limit, reduce,
find, match, and so on.
Pipelining − Most of the stream operations return stream itself so that their result can be
pipelined. These operations are called intermediate operations and their function is to take
input, process them, and return output to the target. collect() method is a terminal operation
which is normally present at the end of the pipelining operation to mark the end of the stream.
Automatic iterations − Stream operations do the iterations internally over the source elements
provided, in contrast to Collections where explicit iteration is required.
Stream pipeline
sources: team, stream operations: filter, sorted, forEach
sinks: collect
team.stream()
.filter(person -> person.age <= 25)
.collect(Collectors.toSet())
.stream()
.sorted(comparing(person -> person.age))
.forEach(person -> System.out.println(person.name));
Sources
Collections
Popular API’s (For example Regex)
String sentence = "Java 8 Stream tutorial";
Stream<String> regExpStream
= Pattern.compile("w").splitAsStream(sentence);
Sources
Infinite
Stream iterateStream = Stream.iterate(0, n -> n + 1).limit(2);
Function
Stream generatedStream = Stream.generate(Math::random).limit(5L);
List<String> arrList = new ArrayList<>();
Stream<String> arrListStream = arrList.stream(); //sized, ordered
List<String> linkedList = new LinkedList<>();
Stream<String> linkedListStream = linkedList.stream(); //sized, ordered
Set<String> hashSet = new HashSet<>();
Stream<String> hashSetStream = hashSet.stream(); //sized, distinct
Set<String> linkedHashSet = new LinkedHashSet<>();
Stream<String> linkedHashSetStream = linkedHashSet.stream(); //sized, distinct, ordered
Set<String> treeSet = new TreeSet<>();
Stream<String> treeSetStream = treeSet.stream(); //sized, distinct, sorted, ordered
source op op op
terminate
ProfitIntermediate
● Stream<S> s.distinct();
● Stream<S> s.filter(Predicate <S>);
● Stream<T> s.map(Function<S, T>);
● Stream<T> s.flatMap(Function<S, Stream<T>>);
● Stream<S> s.peek(Consumer<S>)
● Stream<S> s.sorted()
● Stream<S> s.limit(long);
● Stream<S> s.skip(long);
● Stream<S> s.distinct();
● Stream<S> s.filter(Predicate <S>);
● Stream<T> s.map(Function<S, T>);
● Stream<T> s.map(Function<S, Stream<T>>);
● Stream<S> s.peek(Consumer<S>)
● Stream<S> s.sorted()
● Stream<S> s.limit(long);
● Stream<S> s.skip(long);
● Stream<S> s.unordered();
● Stream<S> s.parallel();
● Stream<S> s.sequential();
Terminal operations = Profit
Terminal operations
iteration: forEach, iterator
search: findFirst, findAny
check: allMatch, anyMatch, noneMatch
aggregation: reduction, collectors
Short-circuiting
All find*
All match*
limit
int number = Stream.iterate(1, n -> n * 2)
.filter(n -> n % 1024 == 0)
.findFirst().get();
Examples
List<Transaction> groceryTransactions = new Arraylist<>();
for(Transaction t: transactions) {
if(t.getType() == Transaction.GROCERY) {
groceryTransactions.add(t);
}
}
Collections.sort(groceryTransactions, new Comparator() {
public int compare(Transaction t1, Transaction t2) {
return t2.getValue().compareTo(t1.getValue());
}
});
List<Integer> transactionIds = new ArrayList<>();
for(Transaction t: groceryTransactions) {
transactionsIds.add(t.getId());
}
Examples
List<Transaction> groceryTransactions = new Arraylist<>();
transactions.Stream()
.filter(t.getType() == Transaction.GROCERY)
Examples
List<Transaction> groceryTransactions = new Arraylist<>();
transactions.Stream()
.filter(t.getType() == Transaction.GROCERY)
.sorted(comparing(t -> t.getValue)
Examples
List<Transaction> groceryTransactions = new Arraylist<>();
transactions.Stream()
.filter(t.getType() == Transaction.GROCERY)
.sorted(comparing(t -> t.getValue).reversed)
Examples
List<Transaction> groceryTransactions = new Arraylist<>();
transactions.Stream()
.filter(t.getType() == Transaction.GROCERY)
.sorted(comparing(t -> t.getValue).reversed)
.map(transaction -> transaction.getId())
Examples
List<Transaction> groceryTransactions = new Arraylist<>();
transactions.Stream()
.filter(t.getType() == Transaction.GROCERY)
.sorted(comparing(t -> t.getValue).reversed)
.map(transaction -> transaction.getId())
.collect(Collectors.toList())
Examples
List<Transaction> groceryTransactions = new Arraylist<>();
transactions.Stream()
.filter(t.getType() == Transaction.GROCERY)
.sorted(comparing(Transaction::getValue).reversed)
.map(Transaction::getId())
.collect(Collectors.toList())
Thanks for your attention!

Mais conteúdo relacionado

Mais procurados

Collections In Java
Collections In JavaCollections In Java
Collections In Java
Binoj T E
 

Mais procurados (20)

Java 8 Streams
Java 8 StreamsJava 8 Streams
Java 8 Streams
 
Java 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & StreamsJava 8 Lambda Expressions & Streams
Java 8 Lambda Expressions & Streams
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
Spring data jpa
Spring data jpaSpring data jpa
Spring data jpa
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Lambda Expressions in Java
Lambda Expressions in JavaLambda Expressions in Java
Lambda Expressions in Java
 
Functional programming with Java 8
Functional programming with Java 8Functional programming with Java 8
Functional programming with Java 8
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
 
Lambda Expressions in Java 8
Lambda Expressions in Java 8Lambda Expressions in Java 8
Lambda Expressions in Java 8
 
Java 8 Default Methods
Java 8 Default MethodsJava 8 Default Methods
Java 8 Default Methods
 
Java Lambda Expressions.pptx
Java Lambda Expressions.pptxJava Lambda Expressions.pptx
Java Lambda Expressions.pptx
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Java Collections
Java  Collections Java  Collections
Java Collections
 
Collections In Java
Collections In JavaCollections In Java
Collections In Java
 
Major Java 8 features
Major Java 8 featuresMajor Java 8 features
Major Java 8 features
 
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of ControlJava Spring framework, Dependency Injection, DI, IoC, Inversion of Control
Java Spring framework, Dependency Injection, DI, IoC, Inversion of Control
 

Semelhante a Introduction to java 8 stream api

FUNctional Programming in Java 8
FUNctional Programming in Java 8FUNctional Programming in Java 8
FUNctional Programming in Java 8
Richard Walker
 
Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrāde
Raimonds Simanovskis
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
b_kathir
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
Raimonds Simanovskis
 

Semelhante a Introduction to java 8 stream api (20)

New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Hot Streaming Java
Hot Streaming JavaHot Streaming Java
Hot Streaming Java
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Tk2323 lecture 9 api json
Tk2323 lecture 9   api jsonTk2323 lecture 9   api json
Tk2323 lecture 9 api json
 
Functional programming in Java 8 - workshop at flatMap Oslo 2014
Functional programming in Java 8 - workshop at flatMap Oslo 2014Functional programming in Java 8 - workshop at flatMap Oslo 2014
Functional programming in Java 8 - workshop at flatMap Oslo 2014
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
Java 8 - Return of the Java
Java 8 - Return of the JavaJava 8 - Return of the Java
Java 8 - Return of the Java
 
Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8
 
FUNctional Programming in Java 8
FUNctional Programming in Java 8FUNctional Programming in Java 8
FUNctional Programming in Java 8
 
Ruby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrādeRuby on Rails Oracle adaptera izstrāde
Ruby on Rails Oracle adaptera izstrāde
 
Java 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually useJava 8 new features or the ones you might actually use
Java 8 new features or the ones you might actually use
 
Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)
 
Belfast JUG 23-10-2013
Belfast JUG 23-10-2013Belfast JUG 23-10-2013
Belfast JUG 23-10-2013
 
Node.js Stream API
Node.js Stream APINode.js Stream API
Node.js Stream API
 
Specification-Driven Development of REST APIs by Alexander Zinchuk
Specification-Driven Development of REST APIs by Alexander Zinchuk   Specification-Driven Development of REST APIs by Alexander Zinchuk
Specification-Driven Development of REST APIs by Alexander Zinchuk
 
Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 
Intro to Spark and Spark SQL
Intro to Spark and Spark SQLIntro to Spark and Spark SQL
Intro to Spark and Spark SQL
 
Developing RESTful WebServices using Jersey
Developing RESTful WebServices using JerseyDeveloping RESTful WebServices using Jersey
Developing RESTful WebServices using Jersey
 
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...Eclipse Collections, Java Streams & Vavr - What's in them for  Functional Pro...
Eclipse Collections, Java Streams & Vavr - What's in them for Functional Pro...
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databasesUsing Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Introduction to java 8 stream api

  • 1. Introduction to Java 8 Stream API Sidlyarevich Vladislav
  • 2. Contacts/samples ● https://github.com/kuksenko/jdk8-lambda-samples ● https://github.com/vlsidlyarevich/Stream-API-Examples ● https://www.youtube.com/watch?v=O8oN4KSZEXE ● https://www.youtube.com/watch?v=i0Jr2l3jrDA
  • 3. Java 8 language features ● Lambdas and Functional Interfaces ● Interface’s Default and Static Methods ● Method References ● Repeating annotations
  • 4. Java 8 language features ● Date/Time API (JSR 310) ● Nashorn JavaScript engine ● Base64 ● Parallel Arrays ● Concurrency
  • 5. Java 8 language features STREAM API!
  • 6. Set<Person> freshBlood = new HashSet<>(); for (Person person : team) { if (person.age <= 25) { freshBlood.add(person); } } List<Person> sortedFreshBlood = new ArrayList<>(freshBlood); Collections.sort(sortedFreshBlood, new Comparator<Person>() { @Override public int compare(Person o1, Person o2) { return Integer.compare(o1.age, o2.age); } }); for (Person person : sortedFreshBlood) { System.out.println(person.name); }
  • 7. team.stream() .filter(person -> person.age <= 25) .collect(Collectors.toSet()) .stream() .sorted(comparing(person -> person.age)) .forEach(person -> System.out.println(person.name));
  • 8. source op op op terminate Profit
  • 9. sources: collections, iterators, api’s operations: filter, map, reduce, etc sinks: collections, locals
  • 10. What is Stream? Multiplicity of values Lazy Single use Not mutate the source Ordered/Unordered Parallel/Sequential IntStream, DoubleStream, LongStream
  • 11. What is Stream? Sequence of elements − A stream provides a set of elements of specific type in a sequential manner. A stream gets/computes elements on demand. It never stores the elements. Source − Stream takes Collections, Arrays, or I/O resources as input source. Aggregate operations − Stream supports aggregate operations like filter, map, limit, reduce, find, match, and so on. Pipelining − Most of the stream operations return stream itself so that their result can be pipelined. These operations are called intermediate operations and their function is to take input, process them, and return output to the target. collect() method is a terminal operation which is normally present at the end of the pipelining operation to mark the end of the stream. Automatic iterations − Stream operations do the iterations internally over the source elements provided, in contrast to Collections where explicit iteration is required.
  • 12. Stream pipeline sources: team, stream operations: filter, sorted, forEach sinks: collect team.stream() .filter(person -> person.age <= 25) .collect(Collectors.toSet()) .stream() .sorted(comparing(person -> person.age)) .forEach(person -> System.out.println(person.name));
  • 13. Sources Collections Popular API’s (For example Regex) String sentence = "Java 8 Stream tutorial"; Stream<String> regExpStream = Pattern.compile("w").splitAsStream(sentence);
  • 14. Sources Infinite Stream iterateStream = Stream.iterate(0, n -> n + 1).limit(2); Function Stream generatedStream = Stream.generate(Math::random).limit(5L);
  • 15. List<String> arrList = new ArrayList<>(); Stream<String> arrListStream = arrList.stream(); //sized, ordered List<String> linkedList = new LinkedList<>(); Stream<String> linkedListStream = linkedList.stream(); //sized, ordered Set<String> hashSet = new HashSet<>(); Stream<String> hashSetStream = hashSet.stream(); //sized, distinct Set<String> linkedHashSet = new LinkedHashSet<>(); Stream<String> linkedHashSetStream = linkedHashSet.stream(); //sized, distinct, ordered Set<String> treeSet = new TreeSet<>(); Stream<String> treeSetStream = treeSet.stream(); //sized, distinct, sorted, ordered
  • 16. source op op op terminate ProfitIntermediate
  • 17. ● Stream<S> s.distinct(); ● Stream<S> s.filter(Predicate <S>); ● Stream<T> s.map(Function<S, T>); ● Stream<T> s.flatMap(Function<S, Stream<T>>); ● Stream<S> s.peek(Consumer<S>) ● Stream<S> s.sorted() ● Stream<S> s.limit(long); ● Stream<S> s.skip(long);
  • 18. ● Stream<S> s.distinct(); ● Stream<S> s.filter(Predicate <S>); ● Stream<T> s.map(Function<S, T>); ● Stream<T> s.map(Function<S, Stream<T>>); ● Stream<S> s.peek(Consumer<S>) ● Stream<S> s.sorted() ● Stream<S> s.limit(long); ● Stream<S> s.skip(long); ● Stream<S> s.unordered(); ● Stream<S> s.parallel(); ● Stream<S> s.sequential();
  • 20. Terminal operations iteration: forEach, iterator search: findFirst, findAny check: allMatch, anyMatch, noneMatch aggregation: reduction, collectors
  • 21. Short-circuiting All find* All match* limit int number = Stream.iterate(1, n -> n * 2) .filter(n -> n % 1024 == 0) .findFirst().get();
  • 22. Examples List<Transaction> groceryTransactions = new Arraylist<>(); for(Transaction t: transactions) { if(t.getType() == Transaction.GROCERY) { groceryTransactions.add(t); } } Collections.sort(groceryTransactions, new Comparator() { public int compare(Transaction t1, Transaction t2) { return t2.getValue().compareTo(t1.getValue()); } }); List<Integer> transactionIds = new ArrayList<>(); for(Transaction t: groceryTransactions) { transactionsIds.add(t.getId()); }
  • 23. Examples List<Transaction> groceryTransactions = new Arraylist<>(); transactions.Stream() .filter(t.getType() == Transaction.GROCERY)
  • 24. Examples List<Transaction> groceryTransactions = new Arraylist<>(); transactions.Stream() .filter(t.getType() == Transaction.GROCERY) .sorted(comparing(t -> t.getValue)
  • 25. Examples List<Transaction> groceryTransactions = new Arraylist<>(); transactions.Stream() .filter(t.getType() == Transaction.GROCERY) .sorted(comparing(t -> t.getValue).reversed)
  • 26. Examples List<Transaction> groceryTransactions = new Arraylist<>(); transactions.Stream() .filter(t.getType() == Transaction.GROCERY) .sorted(comparing(t -> t.getValue).reversed) .map(transaction -> transaction.getId())
  • 27. Examples List<Transaction> groceryTransactions = new Arraylist<>(); transactions.Stream() .filter(t.getType() == Transaction.GROCERY) .sorted(comparing(t -> t.getValue).reversed) .map(transaction -> transaction.getId()) .collect(Collectors.toList())
  • 28. Examples List<Transaction> groceryTransactions = new Arraylist<>(); transactions.Stream() .filter(t.getType() == Transaction.GROCERY) .sorted(comparing(Transaction::getValue).reversed) .map(Transaction::getId()) .collect(Collectors.toList())
  • 29. Thanks for your attention!