List of usage examples for java.util Hashtable get
@SuppressWarnings("unchecked") public synchronized V get(Object key)
From source file:MainClass.java
public static void main(String args[]) { Hashtable ht = new Hashtable(); ht.put("Tokyo", "Japan"); ht.put("Beijing", "China"); ht.put("Bangkok", "Thailand"); String city = "Beijing"; String country = (String) ht.get(city); if (country != null) System.out.println(city + " is located in " + country); else/*from w ww . j av a2 s .c om*/ System.out.println(city + " is not located in the hashtable"); }
From source file:MainClass.java
public static void main(String args[]) { Hashtable hashtable = new Hashtable(); hashtable.put("apple", "red"); hashtable.put("strawberry", "red"); Enumeration e = hashtable.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object v = hashtable.get(k); System.out.println("key = " + k + "; value = " + v); }//from w w w . j a v a 2 s . co m }
From source file:Main.java
public static void main(String args[]) { Hashtable<String, String> hash = new Hashtable<String, String>(); hash.put("1", "one"); hash.put("2", "two"); hash.put("3", "three"); Enumeration keys = hash.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = hash.get(key); System.out.println(key + " : " + value); }/*from w w w.ja v a 2 s . c o m*/ }
From source file:Main.java
public static void main(String args[]) { // create hash table Hashtable<Integer, String> htable1 = new Hashtable<Integer, String>(); // put values in table htable1.put(1, "A"); htable1.put(2, "B"); htable1.put(3, "C"); htable1.put(4, "from java2s.com"); // get values at key 3 System.out.println("Values at key 3 is:" + htable1.get(3)); }
From source file:MainClass.java
public static void main(String[] s) { Hashtable table = new Hashtable(); table.put("key1", "value1"); table.put("key2", "value2"); table.put("key3", "value3"); Enumeration e = table.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); System.out.println(key + " : " + table.get(key)); }//from w ww . j a v a 2s. c o m }
From source file:MainClass.java
public static void main(String[] s) { Hashtable table = new Hashtable(); 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)); }/*w w w. j a va2 s.c o m*/ System.out.println(table.values()); }
From source file:MainClass.java
public static void main(String args[]) { Hashtable<String, Double> balance = new Hashtable<String, Double>(); Enumeration<String> names; String str;/*from ww w.ja v a 2 s .c o m*/ balance.put("A", 3434.34); names = balance.keys(); while (names.hasMoreElements()) { str = names.nextElement(); System.out.println(str + ": " + balance.get(str)); } System.out.println(); }
From source file:PlanetDiameters.java
public static void main(String args[]) { String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" }; float diameters[] = { 4800f, 12103.6f, 12756.3f, 6794f, 142984f, 120536f, 51118f, 49532f, 2274f }; Hashtable hash = new Hashtable(); for (int i = 0, n = names.length; i < n; i++) { hash.put(names[i], new Float(diameters[i])); }/*from w w w .j a v a 2 s. com*/ Enumeration e = hash.keys(); Object obj; while (e.hasMoreElements()) { obj = e.nextElement(); System.out.println(obj + ": " + hash.get(obj)); } }
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 www.ja v a 2 s.c o m*/ JFrame f = new JFrame("KeymapExample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); area.setText("www.\n java2s \n .com."); f.pack(); f.setVisible(true); }
From source file:Main.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 UppercaseAction(); 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); area.setKeymap(newmap);//from w ww .j a v a 2s.c o m JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(area), BorderLayout.CENTER); area.setText("this is a test"); f.setSize(300, 300); f.setVisible(true); }