@[toc]

preface

Java 8 allows you to process the elements of a collection as a Stream. You can think of the collection as a Stream. The Stream is processed and eventually comes out of the end of the pipe, with a node at each point in the pipe representing the flow, such as filter()

The stream with parallelStream

  • Series flow stream
  • The parallel flow parallelStream

This article is just an introduction to serial streams; parallel streams will be covered in another blog post

The collection class uses streams

Methods a

List<String> list = new ArrayList<>();
Stream<String> stream = list.stream();
Copy the code

Way 2

List<String> list = new ArrayList<>();
Stream<List<String>> stream = Stream.of(list);
Copy the code

Array usage streams

Methods a

String[] arr = {"1"."2"."3"};
Stream<String> stream = Stream.of(arr);
Copy the code

Way 2

String[] arr = {"1"."2"."3"};
Stream<String> stream = Arrays.stream(arr);
Copy the code

Common methods of the Stream interface

  • map()

    What map to make of each element (I -> I * I)

  • filter()

    Used to filter elements filter(STR -> str.isempty ())

  • other