Stream computing
What is Stream computing
Big data: storage + computing
Collection framework :(List, Map, Set) MySQL, distributed file storage is essentially to store things;
Calculations should be left to the stream!
package com.test;
import java.util.Arrays;
import java.util.List;
/** * Only one line of code is required to complete this task in one minute. * Now there are 5 users! Filter: * 1, ID must be even * 2, age must be greater than 23 * 3, username to uppercase * 4, username alphabeticssorted backwards * 5, output only one user! * /
public class Test {
public static void main(String[] args) {
User u1 = new User(1."a".21);
User u2 = new User(2."b".22);
User u3 = new User(3."c".23);
User u4 = new User(4."d".24);
User u5 = new User(6."e".25);
// Collection is storage
List<User> list = Arrays.asList(u1, u2, u3, u4, u5);
// The calculation is passed to the Stream
// chain programming
list.stream().filter(u->{return u.getId()%2= =0; }) .filter(u->{return u.getAge()>23; }) .map(u->{returnu.getName().toUpperCase(); }) .sorted((uu1,uu2)->{returnuu2.compareTo(uu1); }) .limit(1) .forEach(System.out::println); }}Copy the code