Wednesday, 12 September 2018

Java 8: Iterate on HashMap

I am writing this simple post for demonstrating the handling of HashMap with Java 8.
Java 8 allows you to iterate on a HashMap with different tools.

Check below code.


Tuesday, 11 September 2018

Java 8: Using optional with nested objects

I am writing this blog for demonstrating the usage of Optional class in java8, with nested objects.

Consider below the class structure,




















Now consider that, you want to extract an email from the Employee object, also you have to avoid null pointer exception. In a traditional way, you have to write a lot of NULL conditions.
Check below code with an Optional class which simplifies your code structure.










I will write a few more posts for using an Optional with collection classes.