Java8-Optional-No.01

mac2022-06-30  94

import java.util.Optional; public class Optional1 { public static void main(String[] args) { Optional<String> optional = Optional.of("bam"); optional.isPresent(); // true optional.get(); // "bam" optional.orElse("fallback"); // "bam" optional.ifPresent((s) -> System.out.println(s.charAt(0))); // "b" } }

转载于:https://www.cnblogs.com/bilaisheng/p/10210909.html

最新回复(0)