Example usage for java.util HashMap put

List of usage examples for java.util HashMap put

Introduction

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

Prototype

public V put(K key, V value) 

Source Link

Document

Associates the specified value with the specified key in this map.

Usage

From source file:Main.java

public static <K, V> HashMap<V, K> invert(Map<K, V> in) {
    HashMap<V, K> result = new HashMap<V, K>();
    for (Map.Entry<K, V> e : in.entrySet()) {
        result.put(e.getValue(), e.getKey());
    }/*  w  w w .  j  ava  2s. co  m*/
    return result;
}

From source file:Main.java

public static <K, V> Map<K, V> map(K[] keys, V[] values) {
    if (keys.length == values.length) {
        HashMap<K, V> result = new HashMap<K, V>(keys.length);

        for (int i = 0; i < keys.length; i++) {
            result.put(keys[i], values[i]);
        }// w w w  .  j  av  a  2  s. c om

        return result;
    } else {
        throw new IllegalArgumentException("arrays must have equal length");
    }
}

From source file:io.github.rhkiswani.javaff.httpclient.util.IOUtil.java

public static Map headersToMap(Header[] headers) {
    HashMap<String, String> map = new HashMap<>();
    for (Header header : headers) {
        map.put(header.getName(), header.getValue());
    }/*from w  ww .j  a  va 2s . c  o m*/
    return map;
}

From source file:Main.java

private static HashMap<Integer, HashMap<Integer, Integer>> createFullAvailableTime() {
    HashMap<Integer, HashMap<Integer, Integer>> availableTime = new HashMap<>();
    for (int hour = 0; hour < 24; hour++) {
        HashMap<Integer, Integer> minutes = new HashMap<>(60);
        for (int minute = 0; minute < 60; minute++) {
            minutes.put(minute, minute);
        }/*from  w  w w  .  ja  v  a 2 s.  co m*/

        availableTime.put(hour, minutes);
    }
    return availableTime;
}

From source file:Main.java

public static HashMap xmltoHashMap222(String xmlFile, String xpath) {
    try {/*from w  w w .  j av  a2s  .c  om*/
        XPathFactory factory = XPathFactory.newInstance();
        XPath xPath = factory.newXPath();
        // XPathExpression xPathExpression =
        // xPath.compile("/history");
        File xmlDocument = new File(xmlFile);
        InputSource inputSource = new InputSource(new FileInputStream(xmlDocument));
        // String root = xPath.evaluate("/", inputSource);
        NodeList nodes = (NodeList) xPath.evaluate(xpath, inputSource, XPathConstants.NODESET);
        HashMap hashmap = new HashMap();
        for (int x = 0; x < nodes.getLength(); x++) {
            hashmap.put(nodes.item(x).getNodeName(), nodes.item(x).getTextContent());
        }
        return hashmap;
    } catch (Exception ex) {
        return null;
    }
}

From source file:StompMessagePublisher.java

private static void send(String host, String port, String user, String pass, String destination, String json,
        StompConnection connection) throws Exception {
    HashMap<String, String> headers = new HashMap<String, String>();
    headers.put(Stomp.Headers.CONTENT_LENGTH, String.valueOf(json.length()));

    connection.send(destination, json, null, headers);
}

From source file:Main.java

public static Map<String, String> deferredDeeplinkToMap(Uri uri) {
    HashMap<String, String> map = new HashMap<String, String>();

    if (null == uri) {
        return map;
    }//from ww w . java 2 s. c  o  m

    map.put("uri", uri.toString());

    return map;
}

From source file:Main.java

public static HashMap<String, String> getMap(String... strings) {
    if (strings.length % 2 != 0) {
        return null;
    }/*  w  w w  .j av  a  2 s  . c o  m*/

    HashMap<String, String> params = new HashMap<String, String>();
    for (int i = 0; i < strings.length - 1; i += 2) {
        params.put(strings[i], strings[i + 1]);
    }

    return params;
}

From source file:Main.java

public static HashMap<String, Object> getMap(String key1, Object value1, String key2, Object value2,
        String key3, Object value3) {
    HashMap<String, Object> result = new HashMap<String, Object>();

    if (key1 != null) {
        result.put(key1, value1);
    }/*from  w  ww.  j a v  a 2  s  .c  om*/

    if (key2 != null) {
        result.put(key2, value2);
    }

    if (key3 != null) {
        result.put(key3, value3);
    }

    return result;
}

From source file:com.projity.main.EclipseMain.java

public static GraphicManager createGraphicManager(Frame frame, String as[], Closure updateViewClosure) {
    Environment.setStandAlone(true);
    Environment.setNewLook(false);
    Environment.setPlugin(true);//www.j av a 2 s  .  co  m
    java.util.HashMap hashmap = ApplicationStartupFactory.extractOpts(as);
    if (updateViewClosure != null)
        hashmap.put("updateViewClosure", updateViewClosure);
    ApplicationStartupFactory applicationstartupfactory = new ApplicationStartupFactory(hashmap);
    return applicationstartupfactory.instanceFromNewSession(frame, true);
}