Some cool features of Java 8

Java 8 has brought in a few cool interesting features which has made Java folks fall in love with Java yet once again. In this short blog, I am going to walk through some of the most widely used features of Java 8. So lets get started…

Static methods of an interface are a perfect way to create some utility stateless methods which really do not require to be present in the class (having a state).

Of course lambdas have also made Java code look cool!

    List<Employees> origEmployeeList = new ArrayList<>();
    List<Employees> filteredEmployeeList = new ArrayList<>();
     for(Employee emp : employeeList) {
         if(emp.getSalary() > 50000) {
             filteredEmployeeList.add(emp);
         }
     }
     return filteredEmployeeList;

Stream way:

return origEmployeeList
     .filter( emp -> emp.getSalary() > 50000)
     .collect(toList());

Also stream helps in parallel processing!