ArrayList: Exercise Solution
Let's look at the solutions for the ArrayList practice problems.
Problem 1: Find employees aged over 50
All the employee names whose age is more than 50.
Solution:
We can iterate the ArrayList using a for
loop or an enhanced for
loop. For each element, we can check that if age is greater than 50, then print the name of the employee.
This can be done easily using streams in Java 8. We will share that solution as well. If you are not familiar with these Java 8 features, then you can use the classic approach.
Get hands-on with 1400+ tech skills courses.