/** * Creates a {@code LinkedHashMap} instance, with a high enough "initial capacity" that it <i>should</i> hold * {@code expectedSize} elements without growth. This behavior cannot be broadly guaranteed, but it is observed to * be true for OpenJDK 1.6. It also can't be guaranteed that the method isn't inadvertently <i>oversizing</i> the * returned map. * * @param expectedSize * the number of elements you expect to add to the returned map * @return a new, empty {@code LinkedHashMap} with enough capacity to hold {@code expectedSize} elements without resizing * @throws IllegalArgumentException * if {@code expectedSize} is negative */ public static <K, V> LinkedHashMap<K, V> newLinkedHashMapWithExpectedSize(int expectedSize) { return new LinkedHashMap<K, V>(capacity(expectedSize)) { private static final long serialVersionUID = 1L; @Override public void clear() { if (isEmpty()) return; super.clear(); } }; }