0
class Solution {
public int[] decompressRLElist(int[] nums) {
    List<Integer>ans = new ArrayList<>();
    for (int i = 0; i < nums.length; i += 2)
        for (int j = 0; j < nums[i]; ++j) 
            ans.add(nums[i + 1]);
    return ans.stream().mapToInt(i -> i).toArray();`

I do not understand the last line.

1 Answers1

0

In general mapToInt maps each item from a stream to int. It also creates an IntStream that has specialized methods for the primitive type int

In this specific case the method is used to convert Integer (The wrapper object) to an int the primitive type. With the IntStreamit is possible to create an actual int[] instead of an Integer[]

It boils down to understanding the difference between primitive types and their wrappers. Especially autoboxing.

https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html

k5_
  • 5,450
  • 2
  • 19
  • 27