Java Utililty Methods Map Create

List of utility methods to do Map Create

Description

The list of methods to do Map Create are organized into topic(s).

Method

HashMapcreateMap_pollutantHourly()
create Mapollutant Hourly
HashMap<String, String> map = new HashMap<String, String>();
map.put("so2", "SulphurDioxide");
map.put("pm10", "PM10");
map.put("co", "CarbonMonoxide");
map.put("no2", "NitrogenDioxide");
map.put("o3", "Ozone");
return map;
MapcreateMapFor(String... args)
create Map For
if (args.length % 2 > 0)
    throw new IllegalArgumentException(
            "The argument count must be event to account for key/value pairs.  You provided " + args.length
                    + " arguments.");
Map<String, String> argMap = new HashMap<String, String>();
for (int i = 0; i < args.length; i = i + 2) {
    argMap.put(args[i], args[i + 1]);
return argMap;
MapcreateMapFromArgs(Object... args)
create Map From Args
Map<String, Object> result = new HashMap<String, Object>();
if (args.length % 2 != 0)
    throw new IllegalArgumentException("There must be a pair number of arguments");
for (int i = 0; i < args.length; i = i + 2) {
    String keyArg = (String) args[i];
    Object arg = args[i + 1];
    result.put(keyArg, arg);
return result;
MapcreateMapFromProperties(Properties stringSubstitutionVariables)
create Map From Properties
HashMap<String, String> map = new HashMap<String, String>();
Set<Entry<Object, Object>> entrySet = stringSubstitutionVariables.entrySet();
for (Entry<Object, Object> entry : entrySet) {
    map.put((String) entry.getKey(), (String) entry.getValue());
return map;
MapcreateMapFromWebsiteList(String[] websiteList)
create Map From Website List
Map<String, Boolean> webMap = new HashMap<String, Boolean>();
for (String website : websiteList) {
    webMap.put(website, true);
return webMap;
Mapmap(final Entry... entries)
map
final HashMap<K, V> map = new HashMap<K, V>(entries.length);
for (final Entry<K, V> entry : entries) {
    map.put(entry.getKey(), entry.getValue());
return Collections.unmodifiableMap(map);
Mapmap(final Object... keysAndValues)
map
return new HashMap<String, Object>() {
        for (int i = 0; i < keysAndValues.length; i += 2) {
            put(String.valueOf(keysAndValues[i]), keysAndValues[i + 1]);
};
Mapmap(final Properties props)
map
final Map<String, Object> map = new HashMap<String, Object>();
for (final Map.Entry<Object, Object> entry : props.entrySet()) {
    map.put((String) entry.getKey(), entry.getValue());
return map;
Mapmap(int initialCapacity)
Constructs a Map capable of holding a specified number of elements.
return new HashMap<K, V>(initialCapacity); 
Mapmap(K key, V value)
Reduces overhead compared to the far more advanced #map(Object) .
Map<K, V> map = new HashMap<>();
map.put(key, value);
return map;