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 .

Technology
©2019-2020 Toolsou All rights reserved,
python Dynamic programming for single source shortest path ( Essence )2020 year 7 month 21 day ASP.NET Core Use of global filters vue monitor Treeselect Change of options experiment 11-1-6 Output string at specified position (20 branch )LED Scrolling text springboot Multi profile configuration ( Essence )2020 year 7 month 15 day Wechat applet template Use of fio Use details Vue el-select obtain label value Determine whether the current object is an array 4 Methods