Before Java 8, Java code was often more verbose, especially when passing behavior as an argument or processing collections.
For example, suppose you want to print every name:
List<String> names = Arrays.asList("A", "B", "C");
for (String name : names) {
System.out.println(name);
}
Java 8 introduced lambda expressions, allowing us to express the same behavior more concisely:
names.forEach(name -> System.out.println(name));
Java 8 also introduced the Stream API, which made operations such as filtering, mapping, sorting, and collecting much easier.
So Java 8 was introduced to provide:
The important idea is:
Java 8 brought functional-style programming into Java while keeping Java object-oriented.
The most important Java 8 features are: