Optional JDK 8
Optional JDK 1.8 Java 8 has introduced a new class Optional in java.util package. It can help in writing a neat code without using too many null checks. By using Optional, we can specify alternate values to return or alternate code to run. This makes the code more readable because the facts which were hidden are now visible to the developer. Advantages of Java 8 Optional: Null checks are not required. No more NullPointerException at run-time. We can develop clean and neat APIs. No more Boiler plate code The above program using Optional Class // Java program with Optional Class import java.util.Optional; public class OptionalDemo{ public static void main(String[] args) { String[] words = new String[10]; Optional<String> checkNull = Optional.ofNullable(words[5]); ...