I just want to clarify something regarding the code below:
public static void ageOverTen(final List<Human> man) {
final List<Human> byAge = man.stream()
.filter(age -> age.getAge() > 10)
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
System.out.println("People over 10 years: " + byAge);
}
In the Java world we all know ArrayList
is not thread safe and it's mutable, so when you create a stream and use a collect()
method, and in it we create an ArrayList
. How does the library affect ArrayList
thread safety and mutation, to make it comply with functional programming concept of immutability?