Last active
March 19, 2020 16:48
-
-
Save oxc/8e8e41e36fed6bb4065453df90449a0e to your computer and use it in GitHub Desktop.
OpenJDK snippet demonstrating correct HashMap constructor usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Constructs a new set containing the elements in the specified collection. | |
* The {@code HashMap} is created with default load factor (0.75) and an initial | |
* capacity sufficient to contain the elements in the specified collection. | |
*/ | |
public HashSet(Collection<? extends E> c) { | |
map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16)); | |
addAll(c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment