Advertisement
sergAccount

Untitled

Feb 6th, 2021
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package com.mycompany.app9;
  7.  
  8. import java.util.List;
  9. import java.util.function.Function;
  10. import java.util.stream.Collectors;
  11. import java.util.stream.Stream;
  12.  
  13. /**
  14.  *
  15.  * @author Admin
  16.  */
  17. public class Main4 {
  18.    
  19.     public static void main(String[] args) {
  20.         // использование map - в качестве параметра функция выполняющая отображения элемента
  21.         System.out.println("F1:");
  22.         Function<String, String> f1 = s -> "PREFIX_" + s;
  23.         //Stream.of("ONE", "TW", "THREE", "FOUR", "A", "B", "C").map(f1).forEach(System.out::println);
  24.         Stream.of("ONE", "TW", "THREE", "FOUR", "A", "B", "C").map(s -> "PREFIX_" + s).forEach(System.out::println);
  25.        
  26.         System.out.println("F2:");
  27.         //Function<String, Integer> f2 = s -> Integer.valueOf(s);
  28.         //Stream.of("1", "2", "3").map(f2).forEach(System.out::println);        
  29.         Stream.of("1", "2", "3").map(s -> Integer.valueOf(s)).forEach(System.out::println);
  30.        
  31.         List<Integer> list = Stream.of("1", "2", "3").map(s -> Integer.valueOf(s)).collect(Collectors.toList());
  32.         for(Integer i: list){
  33.             System.out.println("i=" + i);
  34.         }
  35.     }    
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement