简体   繁体   中英

What is the computational complexity of generating a stream from a hashset in java? We may consider a hashset with $n$ elements and $m$ capacity

What is the computational complexity of generating a stream from a hashset in java? We may consider a hashset with $n$ elements and $m$ capacity.

For example:

Hashset hashset = new HashSet(m);
// ... put n < m elements in the hashset ...
hashset.stream().do something;

I'm not interested in the complexity of do something, just the complexity of building the stream.

Creating the stream is O(1) , it's just the creation of the pipeline structure.

Then, a terminal operation pulls elements from the source (in this case, the hash set) and intermediate operations (if any) are applied.

Creating a stream is declarative ie nothing happens with elements, until a terminal operation is invoked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM