SlideShare a Scribd company logo
1 of 57
Java 8 Stream & C# 3.5 
Trần Duy Quang – May 2014
Agenda 
1. Some notable new things in Java 8 
2. Comparison with LINQ in C# 3.5! 
2
1 
Some new things in Java 8
Notable things 
 Lambda expressions 
 Default methods 
 Method reference 
 Stream 
 Optional 
 New Date & Time API 
 Functional programming 
 Reference (blog post): Everything about Java 8 
4
Lambda expression 
5 
(x, y) -> x + y
Passing function around 
 Dynamically (usually weakly) typed: Javascript 
 Strongly typed: Ruby, Scala, Closure 
6 
Concise Useful 
Paralel 
lizable 
Functional approach
Why lambda in Java now? 
 Clearer than anonymous inner class 
 Basic for stream library 
 shapes.forEach(s -> s.setColor(Color.RED)); 
 A step toward functional programming ! 
7
Main advantage of lambdas 
 Concise & expressive 
8
New way of thinking 
 Encourage functional programming 
 Many classes of problems are easier to solve 
 Code is clearer to read, simpler to maintain 
9
What we actually get? 
 An instance of a class that implements the 
interface that was expected in that place 
 Remember this? 
 Interface that has exactly one abstract method! 
 Functional Interface | Single Abstract Method 
10
Shortening lambda syntax 
 Omit parameter types 
 Expressions instead of blocks 
 Single arguments? Omit parenthesis! 
11
Even better with high-order function 
 High-order function: method return lambdas 
 comparing method of Comparator need function 
specifying how to extract the key 
12
Method reference 
13
Core idea behind 
 Make lambda more succinct! 
 Rather than 
 angles.map(x -> Math.sin(x)); 
 Can be shorthand 
 angles.map(Math::sin); 
14
Predicate 
15
Core idea behind 
 Boolean test(T t) 
 A function to test condition 
16
Benefit: Flexibility 
 Even better with stream (later slides) 
17
Similar things 
 Predicate: boolean test(T t) 
 Check a condition 
 Consumer: void consume(T t) 
 Perform action with the given object 
 BiConsumer: with two parameters 
 Function: R change(T t) 
 Take an object type T and return new object type R 
 BiFunction: with two parameters 
 Supplier: T supply(T t) 
 Return an object with the same type 
18
More convenient helper classes 
 IntConsumer 
 IntFunction<R> 
 IntPredicate 
 IntSupplier 
19
Stream 
20
Stream 
 Wrapper around data sources: arrays, collections… 
 Use lambdas 
 Support map/reduce 
 Lazy evaluation 
 Made parallel atutomatically by compiler 
21
Making streams 
 From individual values 
 Stream.of(val1, val2,…) 
 From array 
 Stream.of(names), Arrays.stream(names) 
 From List (and other collections) 
 names.stream() 
 From a StreamBuilder 
 builder.build() 
 From String 
 String.chars, Arrays.stream(s.split()) 
 From another stream 
 distinct, filter, map, limit, sorted, substream 
22
Turn stream to other data structures 
 Array 
 employees.toArray(Employee[]::new); 
 List 
 names.collect(Collectors.toList()); 
 Set 
 names.collect(Collectors.toSet()); 
23
2 
Comparison with LINQ in C#
Restriction Operators 
25
1. Filtering 
 Find names where “am” occurs 
26
2. Indexed Filtering (tricky) 
 Find names where length <= index + 1 
(generate an indexed stream out of the original array) 
27
Projection Operators 
28
3. Selecting/Mapping 
 Add “Hello “ in front of each names 
29
4. Selecting Many/Flattening 
 Project all the elements in a single collection 
 Java: Transform to entry set, then flatten 
30
Partitioning Operators 
31
5. Taking an Arbitrary Number of Items 
 Obtain the first 4 items 
 Java: convert IntStream into Stream<Integer> 
32
6. Taking Items Based on Predicate 
 Take while having the string that start with “S” 
 Java: don’t have the short-circuited ability, have to 
create Boolean map 
33 
Different meaning from the above!
7. Skipping an Arbitrary Number of Items 
 Skip top items, take the rest 
 Java: 
34
8. Skipping Items Based on Predicate 
 LINQ: SkipWhile 
 Sadly, no way in Java  
35
Ordering Operators 
36
9. Ordering/Sorting Elements 
 Order the elements of a collection alphabetically 
 Java: 
37
10. Ordering/Sorting Elements by 
Specific Criterium 
 Ordering by the length of the string 
 Java 
 Shorthand: 
38
11. Ordering/Sorting Elements by 
Multiple Criteria 
 Sort by length, then by order 
 Java: 
39
Grouping Operators 
40
12.Grouping by a Criterium 
 Group collection of strings by their length 
41
Set Operators 
42
13. Filter Distinct Elements 
 Obtain all the distinct elements from a collection 
43
14. Union of Two Sets 
 Join together two sets of items 
44
Element Operatos 
45
15. First Element 
 Obtain the first element of a collection 
 Java: Maybe better! 
46
Range Operators 
47
16. Generate a Range of Numbers 
 Generate a range of no that are multiples of 11 
48
Quantifier Operators 
49
17. All 
 Do all elements in a collection satisfy a predicate? 
50
18. Any 
 Do any elements in a collection satisfy a predicate? 
51
Merging Operators 
52
19.Zip 
 Combine two collections into a single collection 
53
The last coffee drop 
54
Still left behind by C#! Gambatte, Java!
Make IntelliJ IDEA work with Java 8 
 Make sure you have the latest version (>=13.1.2) 
 Change project language level to 8.0 (F4) 
56
Reference 
 Blog post: Java Streams Preview vs .Net High- 
Order Programming with LINQ 
 Slide: Evolution of Java 
 Slide: Lambda expressions & Stream in Java 8 
 Slide: Java 8 Stream Tutorial Part 1 
 Slide: Java 8 Stream Tutorial part 2 
 Just for fun (Youtube Video 20”): 
 Javapocalypse ^^ 
57

More Related Content

What's hot

Operator overloading
Operator overloadingOperator overloading
Operator overloading
abhay singh
 
jimmy hacking (at) Microsoft
jimmy hacking (at) Microsoftjimmy hacking (at) Microsoft
jimmy hacking (at) Microsoft
Jimmy Schementi
 
Python Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator OverloadingPython Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator Overloading
Ranel Padon
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Kamal Acharya
 

What's hot (20)

New Features of JAVA SE8
New Features of JAVA SE8New Features of JAVA SE8
New Features of JAVA SE8
 
Java 8 new features
Java 8 new featuresJava 8 new features
Java 8 new features
 
Introduction To Functional Programming
Introduction To Functional ProgrammingIntroduction To Functional Programming
Introduction To Functional Programming
 
Functional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singhFunctional programming in java 8 by harmeet singh
Functional programming in java 8 by harmeet singh
 
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)Java 8 Streams And Common Operations By Harmeet Singh(Taara)
Java 8 Streams And Common Operations By Harmeet Singh(Taara)
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Data Summer Conf 2018, “Hands-on with Apache Spark for Beginners (ENG)” — Akm...
Data Summer Conf 2018, “Hands-on with Apache Spark for Beginners (ENG)” — Akm...Data Summer Conf 2018, “Hands-on with Apache Spark for Beginners (ENG)” — Akm...
Data Summer Conf 2018, “Hands-on with Apache Spark for Beginners (ENG)” — Akm...
 
Java 8 streams
Java 8 streams Java 8 streams
Java 8 streams
 
Java.util.concurrent.concurrent hashmap
Java.util.concurrent.concurrent hashmapJava.util.concurrent.concurrent hashmap
Java.util.concurrent.concurrent hashmap
 
Functors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In ScalaFunctors, Applicatives and Monads In Scala
Functors, Applicatives and Monads In Scala
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
jimmy hacking (at) Microsoft
jimmy hacking (at) Microsoftjimmy hacking (at) Microsoft
jimmy hacking (at) Microsoft
 
Operator overloading
Operator overloading Operator overloading
Operator overloading
 
Operator overloading and type conversion in cpp
Operator overloading and type conversion in cppOperator overloading and type conversion in cpp
Operator overloading and type conversion in cpp
 
Python Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator OverloadingPython Programming - VII. Customizing Classes and Operator Overloading
Python Programming - VII. Customizing Classes and Operator Overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Reactive Programming in the Browser feat. Scala.js and PureScript
Reactive Programming in the Browser feat. Scala.js and PureScriptReactive Programming in the Browser feat. Scala.js and PureScript
Reactive Programming in the Browser feat. Scala.js and PureScript
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 

Similar to Java 8 stream and c# 3.5

Java 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CCJava 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CC
JWORKS powered by Ordina
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
Ken Coenen
 

Similar to Java 8 stream and c# 3.5 (20)

New Features in JDK 8
New Features in JDK 8New Features in JDK 8
New Features in JDK 8
 
Java 8 - An Overview
Java 8 - An OverviewJava 8 - An Overview
Java 8 - An Overview
 
New features in jdk8 iti
New features in jdk8 itiNew features in jdk8 iti
New features in jdk8 iti
 
A Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its APIA Brief Conceptual Introduction to Functional Java 8 and its API
A Brief Conceptual Introduction to Functional Java 8 and its API
 
Xebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_finalXebicon2013 scala vsjava_final
Xebicon2013 scala vsjava_final
 
Java 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CCJava 7 & 8 - A&BP CC
Java 7 & 8 - A&BP CC
 
Smart Migration to JDK 8
Smart Migration to JDK 8Smart Migration to JDK 8
Smart Migration to JDK 8
 
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and StreamsIntroduction of Java 8 with emphasis on Lambda Expressions and Streams
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
 
Java 8 Intro - Core Features
Java 8 Intro - Core FeaturesJava 8 Intro - Core Features
Java 8 Intro - Core Features
 
Java 7 & 8
Java 7 & 8Java 7 & 8
Java 7 & 8
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Java8: what's new and what's hot
Java8: what's new and what's hotJava8: what's new and what's hot
Java8: what's new and what's hot
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Java 8 lambda
Java 8 lambdaJava 8 lambda
Java 8 lambda
 
Java 8
Java 8Java 8
Java 8
 
Functional Programming With Scala
Functional Programming With ScalaFunctional Programming With Scala
Functional Programming With Scala
 
What`s New in Java 8
What`s New in Java 8What`s New in Java 8
What`s New in Java 8
 
Java 8 - Project Lambda
Java 8 - Project LambdaJava 8 - Project Lambda
Java 8 - Project Lambda
 
Lambdas and Laughs
Lambdas and LaughsLambdas and Laughs
Lambdas and Laughs
 

Recently uploaded

+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
Health
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 

Recently uploaded (20)

Rums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdfRums floating Omkareshwar FSPV IM_16112021.pdf
Rums floating Omkareshwar FSPV IM_16112021.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
+97470301568>> buy weed in qatar,buy thc oil qatar,buy weed and vape oil in d...
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 

Java 8 stream and c# 3.5

  • 1. Java 8 Stream & C# 3.5 Trần Duy Quang – May 2014
  • 2. Agenda 1. Some notable new things in Java 8 2. Comparison with LINQ in C# 3.5! 2
  • 3. 1 Some new things in Java 8
  • 4. Notable things  Lambda expressions  Default methods  Method reference  Stream  Optional  New Date & Time API  Functional programming  Reference (blog post): Everything about Java 8 4
  • 5. Lambda expression 5 (x, y) -> x + y
  • 6. Passing function around  Dynamically (usually weakly) typed: Javascript  Strongly typed: Ruby, Scala, Closure 6 Concise Useful Paralel lizable Functional approach
  • 7. Why lambda in Java now?  Clearer than anonymous inner class  Basic for stream library  shapes.forEach(s -> s.setColor(Color.RED));  A step toward functional programming ! 7
  • 8. Main advantage of lambdas  Concise & expressive 8
  • 9. New way of thinking  Encourage functional programming  Many classes of problems are easier to solve  Code is clearer to read, simpler to maintain 9
  • 10. What we actually get?  An instance of a class that implements the interface that was expected in that place  Remember this?  Interface that has exactly one abstract method!  Functional Interface | Single Abstract Method 10
  • 11. Shortening lambda syntax  Omit parameter types  Expressions instead of blocks  Single arguments? Omit parenthesis! 11
  • 12. Even better with high-order function  High-order function: method return lambdas  comparing method of Comparator need function specifying how to extract the key 12
  • 14. Core idea behind  Make lambda more succinct!  Rather than  angles.map(x -> Math.sin(x));  Can be shorthand  angles.map(Math::sin); 14
  • 16. Core idea behind  Boolean test(T t)  A function to test condition 16
  • 17. Benefit: Flexibility  Even better with stream (later slides) 17
  • 18. Similar things  Predicate: boolean test(T t)  Check a condition  Consumer: void consume(T t)  Perform action with the given object  BiConsumer: with two parameters  Function: R change(T t)  Take an object type T and return new object type R  BiFunction: with two parameters  Supplier: T supply(T t)  Return an object with the same type 18
  • 19. More convenient helper classes  IntConsumer  IntFunction<R>  IntPredicate  IntSupplier 19
  • 21. Stream  Wrapper around data sources: arrays, collections…  Use lambdas  Support map/reduce  Lazy evaluation  Made parallel atutomatically by compiler 21
  • 22. Making streams  From individual values  Stream.of(val1, val2,…)  From array  Stream.of(names), Arrays.stream(names)  From List (and other collections)  names.stream()  From a StreamBuilder  builder.build()  From String  String.chars, Arrays.stream(s.split())  From another stream  distinct, filter, map, limit, sorted, substream 22
  • 23. Turn stream to other data structures  Array  employees.toArray(Employee[]::new);  List  names.collect(Collectors.toList());  Set  names.collect(Collectors.toSet()); 23
  • 24. 2 Comparison with LINQ in C#
  • 26. 1. Filtering  Find names where “am” occurs 26
  • 27. 2. Indexed Filtering (tricky)  Find names where length <= index + 1 (generate an indexed stream out of the original array) 27
  • 29. 3. Selecting/Mapping  Add “Hello “ in front of each names 29
  • 30. 4. Selecting Many/Flattening  Project all the elements in a single collection  Java: Transform to entry set, then flatten 30
  • 32. 5. Taking an Arbitrary Number of Items  Obtain the first 4 items  Java: convert IntStream into Stream<Integer> 32
  • 33. 6. Taking Items Based on Predicate  Take while having the string that start with “S”  Java: don’t have the short-circuited ability, have to create Boolean map 33 Different meaning from the above!
  • 34. 7. Skipping an Arbitrary Number of Items  Skip top items, take the rest  Java: 34
  • 35. 8. Skipping Items Based on Predicate  LINQ: SkipWhile  Sadly, no way in Java  35
  • 37. 9. Ordering/Sorting Elements  Order the elements of a collection alphabetically  Java: 37
  • 38. 10. Ordering/Sorting Elements by Specific Criterium  Ordering by the length of the string  Java  Shorthand: 38
  • 39. 11. Ordering/Sorting Elements by Multiple Criteria  Sort by length, then by order  Java: 39
  • 41. 12.Grouping by a Criterium  Group collection of strings by their length 41
  • 43. 13. Filter Distinct Elements  Obtain all the distinct elements from a collection 43
  • 44. 14. Union of Two Sets  Join together two sets of items 44
  • 46. 15. First Element  Obtain the first element of a collection  Java: Maybe better! 46
  • 48. 16. Generate a Range of Numbers  Generate a range of no that are multiples of 11 48
  • 50. 17. All  Do all elements in a collection satisfy a predicate? 50
  • 51. 18. Any  Do any elements in a collection satisfy a predicate? 51
  • 53. 19.Zip  Combine two collections into a single collection 53
  • 54. The last coffee drop 54
  • 55. Still left behind by C#! Gambatte, Java!
  • 56. Make IntelliJ IDEA work with Java 8  Make sure you have the latest version (>=13.1.2)  Change project language level to 8.0 (F4) 56
  • 57. Reference  Blog post: Java Streams Preview vs .Net High- Order Programming with LINQ  Slide: Evolution of Java  Slide: Lambda expressions & Stream in Java 8  Slide: Java 8 Stream Tutorial Part 1  Slide: Java 8 Stream Tutorial part 2  Just for fun (Youtube Video 20”):  Javapocalypse ^^ 57

Editor's Notes

  1. In 1974, Liskov and Zilles described a strong-typed language as one in which "whenever an object is passed from a calling function to a called function, its type must be compatible with the type declared in the called function."[1] Jackson wrote, "In a strongly typed language each data area will have a distinct type and each process will state its communication requirements in terms of these types."[2]
  2. Đối với mảng thông thường là EntryType[]::new, nhưng thông thường là nhận một Supplier với đối số là một số nguyên (size) và trả về một mảng rổng. Cũng có hàm toArray không đối số, tuy nhiên nó trả về Object[], và ta không thể cast Object[] sang Blah[] cho dù các thành phần của mảng có kiểu là Blah Thường là phải import static java.util.stream.Collectors.*
  3. Now, the lack of indices in the stream made the algorithm more verbose, but it was also interesting to notice the incompatibilities between primitive-type streams, like IntStream and reference type streams like Stream<Integer>. In this case, I was forced to transform the IntStream returned byintRange into a Stream<Integer> in order to make the argument compatible with the types expected by zip as you can see in the line #4.