We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The order comes from the logic of what you want to do. Imagine it as a pipeline. You want to take the entrySet (key, value), stream it (i.e. "play it one by one"), then map eaxh entry to an integer, and finally keep only the negative ones, and get the first one.
The Optional xan either be empty or have a value. If it does indeed have a value, the whole pipeline would have ended eagerly due to lazy initialization of streams. It would be equivalent with looping through the entrySet and breaking out of the loop as soon as you find a negative value.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
The order comes from the logic of what you want to do. Imagine it as a pipeline. You want to take the entrySet (key, value), stream it (i.e. "play it one by one"), then map eaxh entry to an integer, and finally keep only the negative ones, and get the first one. The Optional xan either be empty or have a value. If it does indeed have a value, the whole pipeline would have ended eagerly due to lazy initialization of streams. It would be equivalent with looping through the entrySet and breaking out of the loop as soon as you find a negative value.