Optional: orElse versus orElseGet
QuizMediumJava onlyAsked in: Accenture, Capgemini, TCS
Optional is a box that holds a value or nothing. Which statements about it are true? Pick all that apply.
Optional.of("asha").orElse(fallback())still calls fallback()Optional.of("asha").orElseGet(() -> fallback())does not call fallback()Optional.of(null)returns an empty OptionalOptional.empty().orElse("x")returns "x"
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.