Java Map Create map(int initialCapacity)

Here you can find the source of map(int initialCapacity)

Description

Constructs a Map capable of holding a specified number of elements.

License

Open Source License

Parameter

Parameter Description
initialCapacity the number of elements this Map is capable of holding before needing to grow.

Return

new empty Map with given initial capacity

Declaration

public static <K, V> Map<K, V> map(int initialCapacity) 

Method Source Code

//package com.java2s;
/*//w  w w.j av a2s. c o m
Copyright (c) 1996-2012 Ariba, Inc.
All rights reserved. Patents pending.
    
$Id: //ariba/platform/util/core/ariba/util/core/MapUtil.java#38 $
    
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
    
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    
*/

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**
    Constructs an  empty Map. The Map will grow on demand
    as more elements are added.
    @return new empty Map
    @aribaapi documented
    */
    public static <K, V> Map<K, V> map() {
        return new HashMap<K, V>(2); // OK
    }

    /**
    Constructs a Map capable of holding a specified number
    of elements. <p/>
        
    To construct a type-safe <code>Map</code>:<ul>
    <li><code>Map&lt;K,V> typesafe = MapUtil.map()</code>
    </ul>
    For a raw <code>Map</code>:<ul>
    <li><code>Map raw = MapUtil.map()</code>
    </ul>
    There will be no compile warnings either way.
        
    @param initialCapacity the number of elements this Map
    is capable of holding before needing to grow.
    @return new empty Map with given initial capacity
    @aribaapi documented
    */
    public static <K, V> Map<K, V> map(int initialCapacity) {
        return new HashMap<K, V>(initialCapacity); // OK
    }

    /**
    Creates new Map with the same contents as the given Map.
        
    To construct a type-safe <code>Map</code>:<ul>
    <li><code>Map&lt;K,V> typesafe = MapUtil.map()</code>
    </ul>
    For a raw <code>Map</code>:<ul>
    <li><code>Map raw = MapUtil.map()</code>
    </ul>
    There will be no compile warnings either way.
        
    @param source source Map
    @return new Map with same contents as <code>source</code>
    @aribaapi documented
    */
    public static <K, V> Map<K, V> map(Map<? extends K, ? extends V> source) {
        return new HashMap<K, V>(source); // OK
    }
}

Related

  1. createMapFromProperties(Properties stringSubstitutionVariables)
  2. createMapFromWebsiteList(String[] websiteList)
  3. map(final Entry... entries)
  4. map(final Object... keysAndValues)
  5. map(final Properties props)
  6. map(K key, V value)
  7. map(K key, V value, Object... keysValues)
  8. map(K key, V value, Object... moreKeysAndValues)
  9. map(K key0, V value0)