Nedir bu Optional ?

Optional<String> chuck = Optional.of("Chuck Norris");
System.out.println(chuck.get());
Optional<String> chuck = Optional.empty();
List<String> list = new ArrayList<>();
list.add("Chuck Norris");
list.add("Arif Pehlivan");
list.add("Mario Jardel");
Optional<List<String>> optList = Optional.of(list);
optList.ifPresent(System.out::println);
Optional<String> chuck = Optional.of("Chuck Norris");
System.out.println(chuck.isPresent() ? "Chuck" : "Norris");
Optional<String> test = Optional.of("Arif Pehlivan");
test.map(String::length);
List<String> list = new ArrayList<>();
list.add("Chuck Norris");
list.add("Arif Pehlivan");
list.add("Mario Jardel");
Optional<List<String>> optList = Optional.of(list);
optList.map(List::size).get();
Optional<String> chuck = Optional.of("Chuck Norris");
chuck.filter(i -> "Chuck Norris".equals(i)).ifPresent(System.out::println);
Optional<String> chuck = Optional.of("Chuck Norris");
System.out.println(chuck.orElse(testOrElse()));
private static String testOrElse(){
System.out.println("Dur yapma");
}
Optional<String> str = Optional.empty();
System.out.println(str.orElseThrow(IllegalArgumentException::new));

--

--

--

Software Engineer www.arifpehlivan.com

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Arif PEHLİVAN

Arif PEHLİVAN

Software Engineer www.arifpehlivan.com

More from Medium

Conversion Between Array and ArrayList in Java

What Is java Date

Anonymous/Unnamed code blocks in Java