3 ms·
The Java standard library also includes an empty set field, so as a performance optimization it's sometimes worth checking if your set will always be empty firs
by nradov 7y ago
The Java standard library also includes an empty set field, so as a performance optimization it's sometimes worth checking if your set will always be empty first and using that rather than instantiating a new HashSet at all.
https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/util/Collections.html#EMPTY_SET https://docs.oracle.com/en/java/javase/13/docs/api/java.base...
- merb 7y agowell the empty set is itself immutable, so depending on the code base the new HashSet(0) was less code.