deyanmalinov

StringArr to IntegerArr with Function

Apr 13th, 2020
158
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.function.Function;
  3.  
  4. public class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.         String[] line = scan.nextLine().split(" ");
  8.         Function<String, Integer> parse = str -> Integer.parseInt(str);
  9.         Integer[] newArr = new Integer[line.length];
  10.         for (int i = 0; i < line.length; i++) {
  11.             newArr[i] = parse.apply(line[i]);
  12.         }
  13.         for (Integer integer : newArr) {
  14.             System.out.print(integer+" ");
  15.         }
  16.     }
  17. }
RAW Paste Data