From d4dac88d3432dcf90b8df3fc65f9521edbffcd2d Mon Sep 17 00:00:00 2001 From: Kavya K Kamath Date: Thu, 10 Oct 2024 17:54:11 +0530 Subject: [PATCH] Update 100_JS_Que --- 100Questions/100_JS_Que | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/100Questions/100_JS_Que b/100Questions/100_JS_Que index a5fa33a..483c534 100644 --- a/100Questions/100_JS_Que +++ b/100Questions/100_JS_Que @@ -1734,3 +1734,26 @@ function MCQ24() { */ } // MCQ24(); + +---------------------******------------------------------------------------ +Explain Optional in java with example? + +Answer: + Optional country = Optional.of("India"); + Optional emp2 = Optional.empty(); + + System.out.println(country.filter(g->g.equals("india"))); + System.out.println(country.filter(g->g.equalsIgnoreCase("india"))); + System.out.println(country.filter(g->g.equals("India")).get()); + + if(country.isPresent()) { + System.out.println("country present is "+country); + } + + country.ifPresent(c->System.out.println("country is "+c)); + System.out.println(country.orElse("No country is present")); + + emp2.ifPresent(c->System.out.println("country here is "+c)); + System.out.println(emp2.orElse("No country is present here")); + +---------------------******------------------------------------------------