I am passing a person list to local method. In this method, I am streaming with passed list and creating a new list. My concern is that if I update for the newly created list, it is affecting the passed list. I am sending piece of code. How to maintain mutable for passed list.
private void checkMutable(List<person> personList) {
List<person> personNewList = personList.stream()
.map(person->person)
.collect(Collectors.toList());
personNewList.stream().forEach(p -> {
p.setEmail("ccc@gmail.com");
p.setName("ccc");
});
personList.stream().forEach(p -> {
System.out.println("name : " + p.getName() + " --- " + "name : " + p.getEmail());
});