语法 H2>
static <T> Stream<T> ofNullable(T t)
import java.util.stream.Stream; public class OfNullableMethodTest1 { public static void main(String args[]) { System.out.println("TutorialsPoint"); int count = (int) Stream.ofNullable(5000).count(); System.out.println(count); System.out.println("Tutorix"); count = (int) Stream.ofNullable(null).count(); System.out.println(count); } }
TutorialsPoint 1 Tutorix 0
import java.util.stream.Stream; public class OfNullableMethodTest2 { public static void main(String args[]) { String str = null; Stream.ofNullable(str).forEach(System.out::println); // prints nothing in the console str = "TutorialsPoint"; Stream.ofNullable(str).forEach(System.out::println); // prints TutorialsPoint } }
TutorialsPoint
以上就是在Java 9中什么时候使用Stream的ofNullable()方法?的详细内容,更多请关注php中文网其它相关文章!
已抢26427个
抢已抢13968个
抢已抢7016个
抢已抢8491个
抢已抢17461个
抢已抢7008个
抢