Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.mycompany.app9;
- import java.util.List;
- import java.util.function.Function;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- /**
- *
- * @author Admin
- */
- public class Main4 {
- public static void main(String[] args) {
- // использование map - в качестве параметра функция выполняющая отображения элемента
- System.out.println("F1:");
- Function<String, String> f1 = s -> "PREFIX_" + s;
- //Stream.of("ONE", "TW", "THREE", "FOUR", "A", "B", "C").map(f1).forEach(System.out::println);
- Stream.of("ONE", "TW", "THREE", "FOUR", "A", "B", "C").map(s -> "PREFIX_" + s).forEach(System.out::println);
- System.out.println("F2:");
- //Function<String, Integer> f2 = s -> Integer.valueOf(s);
- //Stream.of("1", "2", "3").map(f2).forEach(System.out::println);
- Stream.of("1", "2", "3").map(s -> Integer.valueOf(s)).forEach(System.out::println);
- List<Integer> list = Stream.of("1", "2", "3").map(s -> Integer.valueOf(s)).collect(Collectors.toList());
- for(Integer i: list){
- System.out.println("i=" + i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement