Despite the Arrays.stream()'s Java doc not explicitly mentioning "sequential ordered", aren't arrays intrinsically ordered? According to the Stream ordering section: https://docs.oracle.com/en/java/javase/ ... l#Ordering
, a stream ordering is dictated by the "encounter order", in our case, defined by the source operation Arrays.stream(Card.values()), meaning that the stream will actually be ordered, thus takeWhile being deterministic.
Regardless of my statement, would any of the below options have ensured to print HEART ?
Code: Select all
1. Arrays.stream(Card.values())
.sorted()
.takeWhile(Card::isRed)
.forEach(System.out::print);
Code: Select all
2. Stream.of(Card.values())
.takeWhile(Card::isRed)
.forEach(System.out::print);