Example usage for java.util LinkedHashMap LinkedHashMap

List of usage examples for java.util LinkedHashMap LinkedHashMap

Introduction

In this page you can find the example usage for java.util LinkedHashMap LinkedHashMap.

Prototype

public LinkedHashMap(int initialCapacity, float loadFactor) 

Source Link

Document

Constructs an empty insertion-ordered LinkedHashMap instance with the specified initial capacity and load factor.

Usage

From source file:Main.java

public static void main(String[] args) {

    LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>(5, 0.75F);

    // add some values in the map
    map.put("One", 1);
    map.put("Two", 2);
    map.put("Three", 3);

    System.out.println(map);//from  w  w  w.j  av a2s  . c o m

    // clear the map
    map.clear();

    System.out.println(map);
}

From source file:Main.java

public static <K, V> LinkedHashMap<K, V> createLinkedHashMap(int initialCapacity, float loadFactor) {
    return new LinkedHashMap<K, V>(initialCapacity, loadFactor);
}

From source file:Main.java

public static <K, V> LinkedHashMap<K, V> newLinkedHashMap(final int initialCapacity, final float loadFactor) {
    return new LinkedHashMap<K, V>(initialCapacity, loadFactor);
}

From source file:Main.java

/**
 * Creates the linked hash map instance that will hold the given amount of elements. The returned instance is
 * optimized for that size and will not grow until the given number of elements are added.
 * <p>// w  w  w  .ja va2s .c  o m
 * The method is same as <code>new LinkedHashMap&lt;K, V&gt;((int) (size * 1.1), 0.95f)</code>
 *
 * @param <K>
 *            the key type
 * @param <V>
 *            the value type
 * @param size
 *            the preferred size
 * @return the map instance
 */
public static <K, V> Map<K, V> createLinkedHashMap(int size) {
    return new LinkedHashMap<>((int) (size * SIZE_NORMALIZATION), LOAD_FACTOR);
}

From source file:Main.java

/**
 * Creates a <code>LinkedHashMap</code> of the optimal hash capacity for given
 * maximum size and the load factor.// w ww. ja va  2s .  co  m
 * 
 * @param <U> key type
 * @param <V> value type
 * @param size maximum size of the map
 * @param loadFactor usage percentage before a rehash occurs.  Default value for
 *                   Collections framework is 0.75.  Lower values result in less
 *                   chance of collisions at the expense of larger memory footprint
 * @return the created <code>HashMap</code>
 */
public static <U, V> LinkedHashMap<U, V> createLinkedHashMap(int size, float loadFactor) {
    return new LinkedHashMap<U, V>(calcHashCapacity(size, loadFactor), loadFactor);
}

From source file:com.dangdang.ddframe.job.cloud.scheduler.mesos.TaskInfoData.java

/**
 * ?.//from  w  ww  .j  av  a  2s.  c om
 * 
 * @return ??
 */
public byte[] serialize() {
    LinkedHashMap<String, Object> result = new LinkedHashMap<>(2, 1);
    result.put("shardingContext", shardingContexts);
    result.put("jobConfigContext", buildJobConfigurationContext());
    return SerializationUtils.serialize(result);
}