Learn Java Programming - ArrayList spliterator Method Tutorial

preview_player
Показать описание
The spliterator method returns a Spliterator object from the current ArrayList instance. What is a Spliterator? The answer is that a Spliterator is a far more advanced topic than where my tutorial series is thus far. I will be demonstrating how to use a spliterator in a future tutorial when I am on the topic of multi-threading. When you work with large amounts of data, you will strive to create the most efficient and speedy programs possible. Imagine that you have a custom class Box with instance variables of length, height, and width. Now picture that you have an ArrayList containing 5 billion Box objects and you need to find out the average volume of all Boxes in the ArrayList. You can easily loop through each element calculating the volume of each Box object, but that will take some time. The Spliterator interface contains methods for splitting up your ArrayList and running processes on multiple threads which will significantly increase the speed of calculating average volume. With that being said, I really cannot demonstrate something like that scenario because many of the concepts are beyond the scope of this tutorial. However, I will demonstrate a Spliterator iterating on a single thread using the Spliterator forEachRemaining(...) method which functions practically the same as the ArrayList forEach(...) method. If you haven't watched my ArrayList forEach Method Tutorial yet, I would highly recommend doing so.
Рекомендации по теме
welcome to shbcf.ru