Schrödinger's Cat
Java has a Schrödinger's Cat: Optonal<T>
This represents an object that might or might not be present.
Friends These are the primitive "friend" types
for Optional<T>
OptionalIntOptionalDoubleOptionalLong
More About Streams
Sources
- Collections, using
stream() - Arrays, using
Arrays.stream() BufferedReaders, usinglines()String, usingchars()yields anIntStream
Intermediate Operations All of these return streams. They are chainable.
Terminal Operations Purportedly, you want to do something with the stream you generate. In fact, nothing happens until one of these operations is invoked.
count()Counts the items in the stream.sum()Sum the items in a numerical stream.boolean allMatch(Predicate<? super T>)Returnstrueif all items match the predicate.boolean anyMatch(Predicate<? super T>)Returnstrueif any of the items match the predicate.Optional<T> findAny(Predicate<T>)Returns anOptionalcontaining some elemenet for which the the predicate is true, and returns and emptyOptionalotherwise.Optional<T> findFirst(Predicate<T>)Returns anOptionalcontaining the first elemenet for which the the predicate is true, and returns and emptyOptionalotherwise.