# :-: Stream API 一覽
# Stream 接口一覽
## List 轉 Stream
~~~
// 轉stream
list.stream()
// 并發處理
list.parallelStream()
~~~
## filter(過濾)
~~~
Stream<T> filter(Predicate<? super T> predicate);
~~~
## map(元素轉換)
~~~
<R> Stream<R> map(Function<? super T, ? extends R> mapper);
IntStream mapToInt(ToIntFunction<? super T> mapper);
LongStream mapToLong(ToLongFunction<? super T> mapper);
DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper);
~~~
## flatMap(元素轉換)
~~~
<R> Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper);
IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper);
LongStream flatMapToLong(Function<? super T, ? extends LongStream> mapper);
DoubleStream flatMapToDouble(Function<? super T, ? extends DoubleStream> mapper);
~~~
## distinct(去除重復,對象需要重寫 equals、hashCode)
~~~
Stream<T> distinct();
~~~
## sorted(排序)
~~~
Stream<T> sorted();
Stream<T> sorted(Comparator<? super T> comparator);
~~~
## peek(生成新的流:流是單向的,例如用于日志打印)
~~~
Stream<T> peek(Consumer<? super T> action);
~~~
## limit(取前面`n`個元素)
~~~
Stream<T> limit(long maxSize);
~~~
## skip(跳過`n`個元素)
~~~
Stream<T> skip(long n);
~~~
## forEach(遍歷)
~~~
void forEach(Consumer<? super T> action);
void forEachOrdered(Consumer<? super T> action);
~~~
## toArray(轉換成數組)
~~~
Object[] toArray();
<A> A[] toArray(IntFunction<A[]> generator);
~~~
## reduce(結果歸并)
~~~
T reduce(T identity, BinaryOperator<T> accumulator);
Optional<T> reduce(BinaryOperator<T> accumulator);
<U> U reduce(U identity,
BiFunction<U, ? super T, U> accumulator,
BinaryOperator<U> combiner);
~~~
## collect(轉換成集合)
~~~
<R> R collect(Supplier<R> supplier,
BiConsumer<R, ? super T> accumulator,
BiConsumer<R, R> combiner);
<R, A> R collect(Collector<? super T, A, R> collector);
~~~
## 轉list
~~~
// 轉list
Collectors.toList();
// 轉set
Collectors.toSet();
// 轉map
List<TestVo> testList = new ArrayList<>(10);
Map<Long, TestVo> data = releaseList.stream()
.collect(Collectors.toMap(TestVo::getId, x -> x));
~~~
## count(計數)
~~~
long count();
~~~
## 查找
~~~
boolean anyMatch(Predicate<? super T> predicate);
boolean allMatch(Predicate<? super T> predicate);
boolean noneMatch(Predicate<? super T> predicate);
~~~
## 查找
~~~
Optional<T> findFirst();
Optional<T> findAny();
~~~
- 序
- 快速開始
- 環境要求
- 環境準備
- 工程導入
- 工程運行
- 技術基礎
- Java8
- Lambda
- Lambda 受檢異常處理
- Stream 簡介
- Stream API 一覽
- Stream API(上)
- Stream API(下)
- Optional 干掉空指針
- 函數式接口
- 新的日期 API
- Lombok
- SpringMVC
- Swagger
- Mybaties
- Mybaties-plus
- 開發初探
- 新建微服務工程
- 第一個API
- API鑒權
- API響應結果
- Redis 緩存
- 第一個CRUD
- 建表
- 建Entity
- 建Service和Mapper
- 新增API
- 修改API
- 刪除API
- 查詢API
- 單條查詢
- 多條查詢
- 分頁
- 微服務遠程調用
- 聲明式服務調用Feign
- 熔斷機制 Hystrix
- 開發進階