Creating an Optional The Optional<T> class models the absence of a value by a special singleton returned by the Optional.empty()…