java – Collectors. Set implementation in toset()?
•
Java
See English answers > what is default set / list implementation with collectors in Java 8 stream API? 1
Stream.of(1,4,5).collect(Collectors.toSet());
Starting from the Javadoc of the tooff () method, you can read:
I looked at the actual implementation of the toset () method, and it always seems to return HashSet (at least in JDK 11)
I know that the implementation can be changed in the future without violating the contract, but is there a situation that returns an implementation different from the HashSet?
Solution
No, JDK source code clearly indicates collectors Toset() always uses HashSet:: new As you said, of course this may change
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码