Example usage for java.util Hashtable get

List of usage examples for java.util Hashtable get

Introduction

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

Prototype

@SuppressWarnings("unchecked")
public synchronized 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[] s) {
    Hashtable<String, String> table = new Hashtable<String, String>();
    table.put("key1", "value1");
    table.put("key2", "value2");
    table.put("key3", "value3");

    Enumeration e = table.elements();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + table.get(key));
    }/*from   w  ww  .ja  v a2 s .co  m*/

    System.out.println(table.values());
}

From source file:KeymapExample.java

public static void main(String[] args) {
    JTextArea area = new JTextArea(6, 32);
    Keymap parent = area.getKeymap();
    Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent);

    KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK);
    Action actionU = new UpWord();
    newmap.addActionForKeyStroke(u, actionU);

    Action actionList[] = area.getActions();
    Hashtable lookup = new Hashtable();
    for (int j = 0; j < actionList.length; j += 1)
        lookup.put(actionList[j].getValue(Action.NAME), actionList[j]);

    KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK);
    Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction);
    newmap.addActionForKeyStroke(L, actionL);

    KeyStroke W = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK);
    Action actionW = (Action) lookup.get(DefaultEditorKit.selectWordAction);
    newmap.addActionForKeyStroke(W, actionW);

    area.setKeymap(newmap);//from w  w  w  .j a  v a  2  s. com

    JFrame f = new JFrame("KeymapExample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
    area.setText("This is a test.");
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {

    Hashtable<String, String> h = new Hashtable<String, String>();
    h.put("a", "b");
    h.put("c", "d");
    h.put("e", "f");

    for (String str : h.keySet()) {
        System.out.println(str);//from  www.jav  a 2s.  co m
    }
    List<String> v = new ArrayList<String>(h.keySet());
    Collections.sort(v);

    for (String str : v) {
        System.out.println(str + " " + (String) h.get(str));
    }
}

From source file:MainClass.java

public static void main(String args[]) throws IOException {
    Hashtable map = new Hashtable();
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    String line;//  w  ww .j  av  a 2 s  . co  m
    while ((line = br.readLine()) != null) {
        processLine(line, map);
    }
    Enumeration e = map.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + map.get(key));
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    Hashtable hash = new Hashtable(89);
    hash.put("one", "two");
    hash.put("two", "three");
    hash.put("three", "four");
    hash.put("four", "five");
    System.out.println(hash);// w w w . jav a2s  .  c  om
    System.out.println(hash.size());
    Enumeration e = hash.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + hash.get(key));
    }
    Set set = hash.entrySet();
    Iterator it = set.iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        System.out.println(entry.getKey() + " : " + entry.getValue());
    }
}

From source file:WordCount.java

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

    Hashtable map = new Hashtable();
    FileReader fr = new FileReader(args[0]);
    BufferedReader br = new BufferedReader(fr);
    String line;//from ww  w.j  av a  2  s .c om
    while ((line = br.readLine()) != null) {
        processLine(line, map);
    }
    Enumeration e = map.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        System.out.println(key + " : " + map.get(key));
    }
}

From source file:HTDemo.java

public static void main(String args[]) {
    Hashtable<String, Double> balance = new Hashtable<String, Double>();

    Enumeration<String> names;
    String str;//  w  w  w.j av  a2  s  . co  m
    double bal;

    balance.put("A", 3434.34);
    balance.put("B", 123.22);
    balance.put("C", 1378.00);
    balance.put("D", 99.22);
    balance.put("E", -19.08);

    names = balance.keys();
    while (names.hasMoreElements()) {
        str = names.nextElement();
        System.out.println(str + ": " + balance.get(str));
    }
    bal = balance.get("A");
    balance.put("A", bal + 1000);
    System.out.println("A's new balance: " + balance.get("A"));
}

From source file:HTDemo2.java

public static void main(String args[]) {
    Hashtable<String, Double> balance = new Hashtable<String, Double>();

    String str;/*from   w w w .j a v  a  2s  . c om*/
    double bal;

    balance.put("A", 3434.34);
    balance.put("B", 123.22);
    balance.put("C", 1378.00);
    balance.put("D", 99.22);
    balance.put("E", -19.08);

    Set<String> set = balance.keySet();

    Iterator<String> itr = set.iterator();
    while (itr.hasNext()) {
        str = itr.next();
        System.out.println(str + ": " + balance.get(str));
    }

    System.out.println();

    bal = balance.get("A");
    balance.put("A", bal + 1000);
    System.out.println("A's new balance: " + balance.get("A"));
}

From source file:MainClass.java

public static void main(String args[]) {
    Hashtable<String, Double> balance = new Hashtable<String, Double>();

    String str;/*  ww w. ja  v a 2  s  .co m*/
    double bal;

    balance.put("A", 4.34);
    balance.put("B", 3.22);
    balance.put("C", 8.00);
    balance.put("D", 9.22);
    balance.put("E", -9.08);

    Set<String> set = balance.keySet();

    Iterator<String> itr = set.iterator();
    while (itr.hasNext()) {
        str = itr.next();
        System.out.println(str + ": " + balance.get(str));
    }

    System.out.println();

    bal = balance.get("A");
    balance.put("A", bal + 1000);
    System.out.println("A's new balance: " + balance.get("A"));
}

From source file:HashtableDemo.java

public static void main(String[] argv) {

    // Construct and load the hash. This simulates loading a
    // database or reading from a file, or wherever the data is.

    Hashtable h = new Hashtable();

    // The hash maps from company name to address.
    // In real life this might map to an Address object...
    h.put("Adobe", "Mountain View, CA");
    h.put("IBM", "White Plains, NY");
    h.put("Learning Tree", "Los Angeles, CA");
    h.put("Microsoft", "Redmond, WA");
    h.put("Netscape", "Mountain View, CA");
    h.put("O'Reilly", "Sebastopol, CA");
    h.put("Sun", "Mountain View, CA");

    // Two versions of the "retrieval" phase.
    // Version 1: get one pair's value given its key
    // (presumably the key would really come from user input):
    String queryString = "O'Reilly";
    System.out.println("You asked about " + queryString + ".");
    String resultString = (String) h.get(queryString);
    System.out.println("They are located in: " + resultString);
    System.out.println();/*w  w w  . java 2  s  .  c  o  m*/

    // Version 2: get ALL the keys and pairs
    // (maybe to print a report, or to save to disk)
    Enumeration k = h.keys();
    while (k.hasMoreElements()) {
        String key = (String) k.nextElement();
        System.out.println("Key " + key + "; Value " + (String) h.get(key));
    }
}