Nedir bu Optional ?

Arif PEHLİVAN
Oct 31, 2017 · 2 min read
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));

Arif PEHLİVAN

Written by

Software Engineer www.arifpehlivan.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade