I have the code below where I am doing filtering using a filter and replace function inside my map and then I am doing a collect to replace my original array. My question is whether my original objects in inputArr are being discarded and new objects are created or are the same objects being modified when I am doing a collect?

```
public static void test () {
    inputArr.stream().filter(s -> toRemove.contains(s)).
            forEach(u -> u.replaceAll("2","X"));
    inputArr = inputArr.stream().map(x -> filterReplace(x,toRemove)).collect(Collectors.toList());
    System.out.println(inputArr);
}

static String filterReplace(String input, Set<String> toRemove) {
    if (toRemove.contains(input)) {
        return "X";
    }
    else
        return input;
}

```