Telegram Group & Telegram Channel
Java Stream API

Разница между методами map и flatMap

• Метод map принимает функцию, которая вызывается для каждого элемента стрима и преобразует его в другое значение. В результате получается стрим с преобразованными элементами, структура стрима при этом не меняется.

List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<String> strings = numbers.stream()
.map(number -> String.valueOf(number))
.collect(Collectors.toList());


• Метод flatMap принимает функцию, которая преобразует каждый элемент стрима в новый стрим. Затем flatMap объединяет (склеивает) полученные стримы в один общий.
Пример. У нас есть список заказов, а каждый заказ содержит список купленных вещей. Получить список всех купленных вещей можно так:

List<Item> items = orders.stream()
.flatMap(order -> order.getItems().stream())
.collect(Collectors.toList());



group-telegram.com/java_developer/918
Create:
Last Update:

Java Stream API

Разница между методами map и flatMap

• Метод map принимает функцию, которая вызывается для каждого элемента стрима и преобразует его в другое значение. В результате получается стрим с преобразованными элементами, структура стрима при этом не меняется.


List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
List<String> strings = numbers.stream()
.map(number -> String.valueOf(number))
.collect(Collectors.toList());


• Метод flatMap принимает функцию, которая преобразует каждый элемент стрима в новый стрим. Затем flatMap объединяет (склеивает) полученные стримы в один общий.
Пример. У нас есть список заказов, а каждый заказ содержит список купленных вещей. Получить список всех купленных вещей можно так:

List<Item> items = orders.stream()
.flatMap(order -> order.getItems().stream())
.collect(Collectors.toList());

BY Java Developer


Warning: Undefined variable $i in /var/www/group-telegram/post.php on line 260

Share with your friend now:
group-telegram.com/java_developer/918

View MORE
Open in Telegram


Telegram | DID YOU KNOW?

Date: |

The SC urges the public to refer to the SC’s I nvestor Alert List before investing. The list contains details of unauthorised websites, investment products, companies and individuals. Members of the public who suspect that they have been approached by unauthorised firms or individuals offering schemes that promise unrealistic returns Official government accounts have also spread fake fact checks. An official Twitter account for the Russia diplomatic mission in Geneva shared a fake debunking video claiming without evidence that "Western and Ukrainian media are creating thousands of fake news on Russia every day." The video, which has amassed almost 30,000 views, offered a "how-to" spot misinformation. "Russians are really disconnected from the reality of what happening to their country," Andrey said. "So Telegram has become essential for understanding what's going on to the Russian-speaking world." Since January 2022, the SC has received a total of 47 complaints and enquiries on illegal investment schemes promoted through Telegram. These fraudulent schemes offer non-existent investment opportunities, promising very attractive and risk-free returns within a short span of time. They commonly offer unrealistic returns of as high as 1,000% within 24 hours or even within a few hours. Telegram has gained a reputation as the “secure” communications app in the post-Soviet states, but whenever you make choices about your digital security, it’s important to start by asking yourself, “What exactly am I securing? And who am I securing it from?” These questions should inform your decisions about whether you are using the right tool or platform for your digital security needs. Telegram is certainly not the most secure messaging app on the market right now. Its security model requires users to place a great deal of trust in Telegram’s ability to protect user data. For some users, this may be good enough for now. For others, it may be wiser to move to a different platform for certain kinds of high-risk communications.
from us


Telegram Java Developer
FROM American