Junior — Middle
Kuidas saab RxJava teegis ühe objektide voo teisendada teiseks andmevooguks?
sobes.tech AI
Vastus AI-lt
In RxJava, the map operator is used to transform a stream of objects into another. It takes a function that transforms each element of the source stream into a new element of another type.
Example:
Observable<Integer> numbers = Observable.just(1, 2, 3);
Observable<String> strings = numbers.map(number -> "Number: " + number);
strings.subscribe(System.out::println);
The result in the console will be:
Number: 1
Number: 2
Number: 3
Besides map, there are other operators for transforming streams, such as flatMap for working with nested streams.