// Flux
Flux<String> flux1 = Flux.just("a", "b", "c");
String[] array = {"a", "b", "c"};
Flux<String> flux2 = Flux.fromArray(array);
List<String> list = Arrays.asList("a", "b", "c");
Flux<String> flux3 = Flux.fromIterable(list);
Flux<String> flux4 = Flux.fromStream(list.stream());
Flux<String> flux5 = Flux.from(flux4); // copy
Flux<String> emptyFlux = Flux.empty();
flux1.subscribe(
value -> System.out.println(value),
error -> System.out.println(error),
() -> System.out.println("Complete"));
/* 印出
a
b
c
Complete
*/
// Mono
Mono<String> mono1 = Mono.just("a");
Mono<String> mono2 = Mono.from(flux1); // 取flux1的第一個元素
Mono<String> emptyMono = Mono.empty();
mono1.subscribe(
value -> System.out.println(value),
error -> System.out.println(error),
() -> System.out.println("Complete"));
/* 印出
a
Complete
*/
參考:
沒有留言:
張貼留言