List of usage examples for java.util Hashtable Hashtable
public Hashtable()
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"); // create a set view Set st = htable1.keySet();/*from w w w . j ava 2 s .c om*/ System.out.println("Display result: " + st); }
From source file:Main.java
public static void main(String[] args) throws Exception { Hashtable h = new Hashtable(); h.put("string", "AAA"); h.put("int", new Integer(26)); h.put("double", new Double(Math.PI)); FileOutputStream fileOut = new FileOutputStream("hashtable.ser"); ObjectOutputStream out = new ObjectOutputStream(fileOut); out.writeObject(h);//from ww w .j ava 2 s .c o m FileInputStream fileIn = new FileInputStream("h.ser"); ObjectInputStream in = new ObjectInputStream(fileIn); Hashtable h = (Hashtable) in.readObject(); System.out.println(h.toString()); }
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 2 s . c o 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); 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: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"); // create enumeration for keys Enumeration en = htable1.keys(); System.out.println("Display result:"); // display search result while (en.hasMoreElements()) { System.out.println(en.nextElement()); }//from w w w .j ava 2s.co m }
From source file:MainClass.java
public static void main(String args[]) { Hashtable<String, Double> balance = new Hashtable<String, Double>(); Enumeration<String> names; String str;// w w w. ja va 2s . 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:Main.java
public static void main(String[] s) { //object hash table Hashtable<String, String> table = new Hashtable<String, String>(); // populate the table table.put("key1", "value1"); table.put("key2", "value2"); table.put("key3", "from java2s.com"); System.out.println("Initial collection: " + table); // create unmodifiable map Map<String, String> m = Collections.unmodifiableMap(table); // try to modify the collection m.put("key3", "value3"); }
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);// w w w . ja va 2 s . c o 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:Main.java
public static void main(String args[]) { Dictionary ht = new Hashtable(); ht.put("a", "a"); ht.put("b", new Double(2)); ht.put("c", "b"); ht.put("d", new Integer(30)); show(ht);/*from www .j a v a2 s . c o m*/ }
From source file:MainClass.java
public static void main(String args[]) { Hashtable ht = new Hashtable(); ht.put("a", "a"); ht.put("b", new Double(2)); ht.put("c", "b"); ht.put("d", new Integer(30)); show(ht);// w w w . ja va 2s .co m }
From source file:Main.java
public static void main(String[] args) { Hashtable<String, String> ht = new Hashtable<String, String>(); ht.put("1", "One"); ht.put("2", "Two"); ht.put("3", "Three"); Collection c = ht.values();//from w w w.ja v a 2 s. c om Iterator itr = c.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); } c.remove("One"); Enumeration e = ht.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }