Java Reference
In-Depth Information
};
maybeNot.ifPresent(myConsumer);
if(maybeNot.isPresent()){
System.out.println(maybeNot.get().getName());
}
newStocks.add(new Stock("MCD", "McDonalds",
300.0));
Optional<Stock> maybeNow = newStocks.stream()
.findFirst();
maybeNow.ifPresent(myConsumer);
}
}
How It Works
By default, operations are executed in serial stream. However, you can specify that the
Java runtime split the operations between multiple subtasks, thus taking advantage of
multiple CPUs for performance. When operations are executed in this manner, they are
executed in “parallel.” Streams can be partitioned into multiple substreams by the Java
runtime by invoking the parallelStream() intermediate operation. When this op-
eration is invoked, aggregate operations can process the multiple substreams and then
the results will be combined in the end. You can also execute a stream in parallel by in-
voking the operation BaseStream.parallel .
Summary
This chapter looked at various data structures and how to work with them. First, you
took a look at Enums and learned how to utilize them effectively. Next, we covered the
basics of Arrays and ArrayList , and learned how to iterate over elements within
these structures. The chapter also covered Java generics, which allow you to decouple
object types from container types, providing for more type-safe and efficient code.
Search WWH ::




Custom Search