I have a methods that prints the name of a person from a given list if it has the indicated age. This method is implemented using the imperative and then functional approach.
public static void printPerson(int age) {
for(Person p: list) {
if(p.age == age) {
System.out.println(p.name)
}
}
}
Functional approach:
public static void printPerson(int age) {
list.stream()
.filter(p -> p.age == age)
.forEach(p -> System.out.println(p.name));
}
The question is, besides readability, how else we can compare these two approaches and what would be the evaluation for each of those attributes. For example, which one has higher memory footprint, which one introduces least overhead, or has a higher response time. What other attributes (i.e., non-functional requirements) can be discussed?