
Important New Features in java 8...... 1) forEach() method in Iterable interface Whenever we need to traverse through a Collection, we need to create an Iterator whose whole purpose is to iterate over and then we have business logic in a loop for each of the elements in the Collection. We might get ConcurrentModificationException if iterator is not used properly. Java 8 has introduced forEach method in java.lang.Iterable interface so that while writing code we focus on business logic only. forEach method takes java.util.function.Consumer object as argument, so it helps in having our business logic at a separate location that we can reuse. Let’s see forEach usage with simple example. 2) default and static methods in Interfaces If you read forEach method details carefully, you will notice that it’s defined in Iterable interface but we know that interfaces can’t have method body. Fro...