1 Knowledge framework

   Let's start with the previous picture Java8 in ” flow ” Introduction of , Significance and advantages .

2 tradition Java Deficiency of set

2.1 tradition Java aggregate

   Set is Java A very versatile collection in , Because of its advantages in data processing , Almost any one Java Applications are designed to Java Assembly manufacturing and processing .
   however , A traditional Java Set is just right Java Collection of internal data for simple addition , Delete and other operations , And the type of data processed is limited .
   When complex business logic processing is involved , A large number of iterators are needed to complete the requirements , Cumbersome operation , Heavy workload .

2.2 Declarative operation

   Database we are familiar with SQL operation . for example :
SELECT name FROM users WHERE age < 30
   above SQL Query statement can select age less than 30 User name for year old users .
ad locum , We just need to declare our requirements explicitly ” Age less than 30 User name for year old users ” That's it , Without thinking about how to achieve it .
   that ,Java How can collections implement such explicit declaration operations ?

3 What is flow

3.1 Example explanation

   Here is an example , To better understand what is ” flow ”.
   Now here are some pebbles , colour , Unequal quality .

3.1.1 demand

1. The selected mass is less than 500g Pebbles of , and 2. Line them up in order of mass .

3.1.2 Java7( aggregate ) realization

1. Filter elements using iterators
List<Stone> stoneList = new ArrayList<Stone>(); for (Stone s : stoneLine) { if
(s.getWeight() <500) { stoneList.add(s); } }
2. Using anonymous class to sort the quality of pebbles ( From big to small )
Collections.sort(stoneList, new Comparator<Stone>() { public int compare(Stone
s1, Stone s2) {return Integer.compare(s1.getWeight(), s2.getWeight()); } });
3. Line up the pebbles in a good order ( Put it together )
List<String> lastStoneList = new ArrayList<Stone>(); for (Stone s : stoneList)
{ lastStoneList.add(s.getName()); } }
3.1.3 Java8(Stream) realization
List<String> lastStoneList = stoneLine.stream() .filter(s -> s.getWeight() <
500)// The selected mass is less than 500g Pebbles of .sorted(comparing(Stone::getWeight))// Sort by quality .map(Stone
::getName)// Extract the names of pebbles that meet the requirements .collect(toList());// Save name to List in
3.2 What is flow

   flow , Is a series of data items , It's not a data structure .
   Flows can be correlated with algorithms and calculations , It just doesn't show up explicitly , It's implicit inside .

4 Advantages of flow

   flow , Solved two problems ,1. Realize you directly ” What do you want ”,2. Parallel processing is possible .
   flow , The essence of , aggregate Lambda expression , To tradition Java Function enhancement of collection .
  Java 8 In Stream
It's the right set (Collection) Object enhancements , It focuses on the convenience of collection objects , Efficient aggregation operations (aggregate
operation), Or mass data operation (bulk data operation).Stream API With the same new Lambda
expression , Greatly improve programming efficiency and program readability . At the same time, it provides two modes of serial and parallel aggregation operation , Concurrent mode can make full use of the advantages of multi-core processor , use fork/join
Split tasks and accelerate processing in parallel . It is usually difficult and error prone to write parallel code , But use Stream API
No need to write a line of multithreaded code , It is very convenient to write high performance concurrent programs . So ,Java 8 For the first time java.util.stream
Is a functional language + The product of comprehensive influence in multi-core Era .

©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library )Unity3D of UGUI Basics -- Three modes of canvas os Simple use of module computer network --- Basic concepts of computer network ( agreement , system )html Writing about cherry trees , Writing about cherry trees Some East 14 Pay change 16 salary , Sincerity or routine ?Unity-Demo Examples ✨ realization UI- Backpack equipment drag function 06【 Interpretation according to the frame 】 Data range filtering -- awesome java Four functional interfaces ( a key , simple )