Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Optional;

public class Main {
    public static void main(String[] args) {
        Optional<String> optional1 = Optional.empty();
        Optional<String> optional2 = Optional.of("DEMO");

        System.out.println("optional2.get = " + optional2.get());
        System.out.println("optional1.orElse = " + optional1.orElse("Something else"));
        optional2.ifPresent(System.out::println);
        System.out.println("optional1.isPresent = " + optional1.isPresent());

    }

}