Creating Strong Password using Stream API of Java 9
Creating a strong password has never been so easy in Java when Stream API is used. Stream API is introduced in Java SE 8 and has changed the way we think and develop in Java together with the functional programming and lambda expressions. Java 9 will improve the Stream API with new convenience methods. Stream API is basically designed to work with collections in functional style. I would like to exemplify this new way of thinking simply by creating a strong password:
There are new methods added to the Stream interface in Java 9: dropWhile, takeWhile, ofNullable. Now, we allow the application programmer to define what strong password is and create a password that conforms that definition:
StrongPassword class defines the strongness of the password:
One example output of the execution is given below:
You could retrieve the code from this URL as NetBeans IDE Dev (Build 2017-06-14-0001) project.