This repository was archived by the owner on Feb 10, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ # <img src =" https://raw.githubusercontent.com/bobocode-projects/resources/master/image/logo_transparent_background.png " height =50/ > Stream API tutorial
2+
3+ This is the tutorial on Stream API and functional programming techniques
4+ ### Pre-conditions :heavy_exclamation_mark :
5+ You're supposed to be familiar with OOP, have basic knowledge of JDK, and be able to write Java code.
6+ ### Related exercises :muscle :
7+ *
8+ ### See also :point_down :
9+ * [ Tutorial on Lambdas] ( https://github.com/bobocode-projects/java-functional-features-tutorial/tree/master/lambdas )
10+ * [ Tutorial on Optional] ( https://github.com/bobocode-projects/java-functional-features-tutorial/tree/master/optional )
11+ ##
12+ * Stream API* provide an ability to ** process sequences of data elements in a declarative way** and ** simplify the task of
13+ performing operations in parallel**
14+
15+ The simplest example is the task of filtering a collection. Using ** imperative** old-style approach we specify ** HOW the task
16+ should be done** . E.g. dealing with iteration, and storing each element in a new ` ArrayList ` . This way of processing is also
17+ called * external iteration* . * Stream API* and it's ** declarative** approach allows us to specify ** WHAT should be done** , without
18+ actually dealing with iteration and elements. This approach is also called * internal iteration* .
19+
20+ Imperative style:
21+ ``` java
22+ List<Account > gmailAccounts = new ArrayList<> ();
23+ for (Account account : accounts) {
24+ if (account. getEmail(). endsWith(" @gmail.com" )) {
25+ gmailAccounts. add(account);
26+ }
27+ }
28+ ```
29+ Declarative style using * Stream API* :
30+ ``` java
31+ List<Account > gmailAccounts = accounts. stream()
32+ .filter(a - > a. getEmail(). endsWith(" @gmail" ))
33+ .collect(toList());
34+ ```
You can’t perform that action at this time.
0 commit comments