Collection
instances.- Author:
- Hannes Wellmann
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> E
getElement
(Iterable<E> iterable, int index) Returns from the givenIterable
the element with the givenindex
.static <K,
V> HashMap<K, V> newHashMapWithExpectedSize
(int expectedSize) Returns aHashMap
with an initial capacity that is sufficient to holdexpectedSize
mappings without rehashing its internal backing storage.static <E> HashSet<E>
newHashSetWithExpectedSize
(int expectedSize) Returns aHashSet
with an initial capacity that is sufficient to holdexpectedSize
elements without rehashing its internal backing storage.static <K,
V> LinkedHashMap<K, V> newLinkedHashMapWithExpectedSize
(int expectedSize) Returns aLinkedHashMap
with an initial capacity that is sufficient to holdexpectedSize
mappings without rehashing its internal backing storage.static <E> LinkedHashSet<E>
newLinkedHashSetWithExpectedSize
(int expectedSize) Returns aLinkedHashSet
with an initial capacity that is sufficient to holdexpectedSize
elements without rehashing its internal backing storage.
-
Method Details
-
newHashMapWithExpectedSize
Returns aHashMap
with an initial capacity that is sufficient to holdexpectedSize
mappings without rehashing its internal backing storage.The returned
HashMap
has a capacity that is the specified expected size divided by the load factor of the Map, which is sufficient to holdexpectedSize
mappings without rehashing. As the Javadoc ofHashMap
states: "If the initial capacity is greater than the maximum number of entries divided by the load factor, no rehash operations will ever occur".- Type Parameters:
K
- the type of keys in the returnedHashMap
V
- the type of values in the returnedHashMap
- Parameters:
expectedSize
- of mappings that will be put into the returnedHashMap
- Returns:
- an empty
HashMap
with sufficient capacity to hold expectedSize mappings - See Also:
-
newLinkedHashMapWithExpectedSize
Returns aLinkedHashMap
with an initial capacity that is sufficient to holdexpectedSize
mappings without rehashing its internal backing storage.Because
LinkedHashMap
extendsHashMap
it inherits the issue that the capacity is not equivalent to the number of mappings it can hold without rehashing. SeenewHashMapWithExpectedSize(int)
for details.- Type Parameters:
K
- the type of keys in the returnedLinkedHashMap
V
- the type of values in the returnedLinkedHashMap
- Parameters:
expectedSize
- of mappings that will be put into the returnedLinkedHashMap
- Returns:
- an empty
LinkedHashMap
with sufficient capacity to hold expectedSize mappings - See Also:
-
newHashSetWithExpectedSize
Returns aHashSet
with an initial capacity that is sufficient to holdexpectedSize
elements without rehashing its internal backing storage.Because a
HashSet
is backed by aHashMap
it inherits the issue that the capacity is not equivalent to the number of elements it can hold without rehashing. SeenewHashMapWithExpectedSize(int)
for details.- Type Parameters:
E
- the type of elements in the returnedHashSet
- Parameters:
expectedSize
- of elements that will be add to the returnedHashSet
- Returns:
- an empty
HashSet
with sufficient capacity to hold expectedSize elements - See Also:
-
newLinkedHashSetWithExpectedSize
Returns aLinkedHashSet
with an initial capacity that is sufficient to holdexpectedSize
elements without rehashing its internal backing storage.Because a
LinkedHashSet
is backed by aHashMap
it inherits the issue that the capacity is not equivalent to the number of elements it can hold without rehashing. SeenewHashMapWithExpectedSize(int)
for details.- Type Parameters:
E
- the type of elements in the returnedLinkedHashSet
- Parameters:
expectedSize
- of elements that will be add to the returnedLinkedHashSet
- Returns:
- an empty
LinkedHashSet
with sufficient capacity to hold expectedSize elements - See Also:
-
getElement
Returns from the givenIterable
the element with the givenindex
.The order to which the index applies is that defined by the
Iterable.iterator()
.- Type Parameters:
E
- the type of elements in theIterable
- Parameters:
iterable
- the Iterable from which the element atindex
is returnedindex
- the index of the returned element- Returns:
- the element with
index
in theiterable
-