Array /Stream API problem
I'm trying to print the numbers of an array to the second power in one row separated by single whitespaces using stream API like this: int[] arr = {5, 3, 1}; Arrays.stream(arr) .map(x -> (int)Math.pow(x, 2)) .map(x -> x + " ") .forEach(System.out::print); In this row --> .map(x -> x + " ") i get an exception ( Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from String to int ) The strange thing if I try the same this using this method but on an ArrayList it is working fine: List<Integer> nums = new ArrayList<Integer>(); nums.add(3); nums.add(2); nums.stream() .map(x -> (int)Math.pow(x, 2)) .map(x -> x + " ") .forEach(System.out::print); If anyone could help me I would really appreciate it :)