Class CollectionUtil
- java.lang.Object
-
- org.jgrapht.util.CollectionUtil
-
public class CollectionUtil extends Object
Utility class to createCollectioninstances.- Author:
- Hannes Wellmann
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <K,V>
HashMap<K,V>newHashMapWithExpectedSize(int expectedSize)Returns aHashMapwith an initial capacity that is sufficient to holdexpectedSizemappings without rehashing its internal backing storage.static <E> HashSet<E>newHashSetWithExpectedSize(int expectedSize)Returns aHashSetwith an initial capacity that is sufficient to holdexpectedSizeelements without rehashing its internal backing storage.static <K,V>
LinkedHashMap<K,V>newLinkedHashMapWithExpectedSize(int expectedSize)Returns aLinkedHashMapwith an initial capacity that is sufficient to holdexpectedSizemappings without rehashing its internal backing storage.static <E> LinkedHashSet<E>newLinkedHashSetWithExpectedSize(int expectedSize)Returns aLinkedHashSetwith an initial capacity that is sufficient to holdexpectedSizeelements without rehashing its internal backing storage.
-
-
-
Method Detail
-
newHashMapWithExpectedSize
public static <K,V> HashMap<K,V> newHashMapWithExpectedSize(int expectedSize)
Returns aHashMapwith an initial capacity that is sufficient to holdexpectedSizemappings without rehashing its internal backing storage.The returned
HashMaphas a capacity that is the specified expected size divided by the load factor of the Map, which is sufficient to holdexpectedSizemappings without rehashing. As the Javadoc ofHashMapstates: "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 returnedHashMapV- the type of values in the returnedHashMap- Parameters:
expectedSize- of mappings that will be put into the returnedHashMap- Returns:
- an empty
HashMapwith sufficient capacity to hold expectedSize mappings - See Also:
HashMap
-
newLinkedHashMapWithExpectedSize
public static <K,V> LinkedHashMap<K,V> newLinkedHashMapWithExpectedSize(int expectedSize)
Returns aLinkedHashMapwith an initial capacity that is sufficient to holdexpectedSizemappings without rehashing its internal backing storage.Because
LinkedHashMapextendsHashMapit 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 returnedLinkedHashMapV- the type of values in the returnedLinkedHashMap- Parameters:
expectedSize- of mappings that will be put into the returnedLinkedHashMap- Returns:
- an empty
LinkedHashMapwith sufficient capacity to hold expectedSize mappings - See Also:
HashMap
-
newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
Returns aHashSetwith an initial capacity that is sufficient to holdexpectedSizeelements without rehashing its internal backing storage.Because a
HashSetis backed by aHashMapit 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
HashSetwith sufficient capacity to hold expectedSize elements - See Also:
HashMap
-
newLinkedHashSetWithExpectedSize
public static <E> LinkedHashSet<E> newLinkedHashSetWithExpectedSize(int expectedSize)
Returns aLinkedHashSetwith an initial capacity that is sufficient to holdexpectedSizeelements without rehashing its internal backing storage.Because a
LinkedHashSetis backed by aHashMapit 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
LinkedHashSetwith sufficient capacity to hold expectedSize elements - See Also:
HashMap
-
-