/
EugenyCh7
/
JavaAndScalaLessons
Обзор
Документация
Войти
/
EugenyCh7
/
JavaAndScalaLessons
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
JavaTest/src/ch6/ex15/Main.java
22 строки
695 B
Eugeny Chekmarev
IDEA update
15 июн 2021, 21:11
15 июн 2021, 21:11
47fadf9
Код
Авторство
О чём код?
package ch6.ex15; import java.util.ArrayList; import java.util.function.Function; public class Main { public static void main(String[] args) { ArrayList<Integer> source = new ArrayList<>(); for (int i = 0; i < 10; i++) source.add(i); ArrayList<String> result; result = map(source, (x) -> String.format("%d ^ 2 = %d", x, x * x)); System.out.println(source); System.out.println(result); } public static <T, R> ArrayList<R> map(ArrayList<T> source, Function<T, R> filter) { ArrayList<R> result = new ArrayList<>(source.size()); for (T t : source) result.add(filter.apply(t)); return result; } }