Example usage for java.util HashMap get

List of usage examples for java.util HashMap get

Introduction

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

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:Main.java

public static void main(String[] args) {
    ReferenceQueue referenceQueue = new ReferenceQueue();
    Object object = new Object() {
        public String toString() {
            return "Referenced Object";
        }/*from  www .  ja v a2 s . c om*/
    };

    Object data = new Object() {
        public String toString() {
            return "Data";
        }
    };

    HashMap map = new HashMap();
    Reference reference = new SoftReference(object, referenceQueue);

    map.put(reference, data);

    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    object = null;
    data = null;

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());
}

From source file:Main.java

public static void main(String args[]) {
    HashMap<Integer, String> newmap = new HashMap<Integer, String>();

    // populate hash map
    newmap.put(1, "tutorials");
    newmap.put(2, "from");
    newmap.put(3, "java2s.com");

    // get value of key 3
    String val = (String) newmap.get(3);

    // check the value
    System.out.println("Value for key 3 is: " + val);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    HashMap<Integer, Callable<String>> m = new HashMap<Integer, Callable<String>>() {
        {/*from  w  w  w  . j  a v a  2s .  co  m*/
            put(0, () -> {
                return "n";
            });
            put(1, () -> {
                return "m";
            });
        }
    };
    System.out.println(m.get(0).call());
}

From source file:Main.java

public static void main(String[] args) {
    HashMap<Character, Integer> map = new HashMap<Character, Integer>();
    String test = "BUNANA";
    char[] chars = test.toCharArray();

    for (int i = 0; i < chars.length; i++) {
        if (!map.containsKey(chars[i])) {
            map.put(chars[i], 1);//www.  j  av a  2s.  c om
        }
        map.put(chars[i], map.get(chars[i]) + 1);
    }

    System.out.println(map.toString());
}

From source file:Main.java

public static void main(String[] args) {
    ReferenceQueue referenceQueue = new ReferenceQueue();
    Object object = new Object() {
        public String toString() {
            return "Referenced Object";
        }/*  ww  w .j a v a 2  s .  co  m*/
    };

    Object data = new Object() {
        public String toString() {
            return "Data";
        }
    };

    HashMap map = new HashMap();
    Reference reference = null;
    System.out.println("Testing WeakReference.");
    reference = new WeakReference(object, referenceQueue);

    map.put(reference, data);

    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    object = null;
    data = null;

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());
}

From source file:Main.java

public static void main(String[] args) {
    ReferenceQueue referenceQueue = new ReferenceQueue();
    Object object = new Object() {
        public String toString() {
            return "Referenced Object";
        }/* w  ww.j  a  va2s. c  o m*/
    };

    Object data = new Object() {
        public String toString() {
            return "Data";
        }
    };

    HashMap map = new HashMap();
    Reference reference = null;
    System.out.println("Testing PhantomReference.");
    reference = new PhantomReference(object, referenceQueue);

    map.put(reference, data);

    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());

    object = null;
    data = null;

    System.gc();
    System.out.println(reference.get());
    System.out.println(map.get(reference));
    System.out.println(reference.isEnqueued());
}

From source file:Main.java

public static void main(String[] args) {
    HashMap<String, Integer> myMap = new HashMap<String, Integer>();

    myMap.put("a", 1);
    myMap.put("b", 2);
    myMap.put("c", 3);

    Set<String> stStrKeys = myMap.keySet();
    Iterator<String> itrs = stStrKeys.iterator();
    while (itrs.hasNext()) {
        String s = itrs.next();/*from  w w  w. j av  a  2s  .  co m*/
        System.out.println(s + ": " + myMap.get(s));
    }
}

From source file:Main.java

public static void main(String[] args) {
    HashMap<String, Integer> map = new HashMap<String, Integer>();
    map.put("d", 5);
    map.put("c", 4);
    map.put("b", 2);
    map.put("a", 1);

    Integer value[] = new Integer[map.size()];

    Set keySet = map.keySet();//  w w  w .j ava  2  s.  c o m
    Iterator t = keySet.iterator();
    int a = 0;
    while (t.hasNext()) {
        value[a] = map.get(t.next());
        a++;
    }

    Arrays.sort(value);

    for (int i = 0; i < map.size(); i++) {
        t = keySet.iterator();
        while (t.hasNext()) {
            String temp = (String) t.next();
            if (value[i].equals(map.get(temp))) {
                System.out.println(value[i] + " = " + temp);
            }
        }
    }
}

From source file:edu.ucsd.ccdb.cil.xml2json.XML2JsonDriver.java

public static void main(String[] args) throws Exception {
    boolean debug = false;
    long debugID = 29;
    XML2JsonUtil xutil = new XML2JsonUtil();
    CCDBXMLResource xmlResource = new CCDBXMLResource();
    HashMap<String, String> xmlMap = xmlResource.getXMLPaths();
    DBUtil dbutil = new DBUtil();
    Vector<Long> vIDs = dbutil.getCCDBPublicIDs();

    for (int i = 0; i < vIDs.size(); i++) {

        long id = vIDs.get(i);
        if (!debug) {
            System.out.println("-----Working on:" + id);
            String path = xmlMap.get(id + "");
            //System.out.println(path);
            String xml = xmlResource.getXMLContent(new File(path));
            String json = xutil.xml2Json(xml);
            File f = new File(Constants.jsonOutputFolder2 + "/" + id + ".json");
            xutil.outputStringToFile(f, json);
        } else if (debugID == id) {
            System.out.println("-----Working on:" + id);
            String path = xmlMap.get(id + "");
            //System.out.println(path);
            String xml = xmlResource.getXMLContent(new File(path));
            String json = xutil.xml2Json(xml);
            File f = new File(Constants.jsonOutputFolder2 + "/" + id + ".json");
            xutil.outputStringToFile(f, json);
        }/* w w w. j a  v  a2s  .  co  m*/
    }

}

From source file:br.usp.ime.lapessc.xflow2.core.VCSMiner.java

public static void main(String[] args) {
    HashMap<String, List<FolderArtifactDTO>> map = new HashMap<String, List<FolderArtifactDTO>>();

    List<FolderArtifactDTO> list = map.get("path");
    if (list == null)
        list = new ArrayList<FolderArtifactDTO>();
    list.add(new FolderArtifactDTO());
    map.put("path", list);
    System.out.println(map);/* w w  w.ja v  a 2s .co m*/
}