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"); System.out.println("Initial hash table value: " + htable1); // remove element at key 3 htable1.remove(3);/* ww w . j av a 2 s.c o m*/ System.out.println("Hash table value after remove: " + htable1); }
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"); System.out.println("Initial hash table value: " + htable1); String returnval = (String) htable1.put(1, "C"); System.out.println("Return value: " + returnval); System.out.println("New hash table value: " + htable1); }
From source file:Main.java
public static void main(String args[]) { Hashtable<Integer, String> htable = new Hashtable<Integer, String>(); // put values into the table htable.put(1, "A"); htable.put(2, "B"); htable.put(3, "C"); htable.put(4, "from java2s.com"); // create enumeration Enumeration<String> e = htable.elements(); System.out.println("Display result:"); // display search result while (e.hasMoreElements()) { System.out.println(e.nextElement()); }/*from w w w .ja va 2 s . co m*/ }
From source file:HTDemo.java
public static void main(String args[]) { Hashtable<String, Double> balance = new Hashtable<String, Double>(); Enumeration<String> names; String str;//from www .j a v a2s . 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: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"); Map m = Collections.unmodifiableMap(table); m.put("key3", "value3"); System.out.println(m);// w w w.ja v a2s. c o m }
From source file:Main.java
public static void main(String args[]) { // create two hash tables Hashtable<Integer, String> htableclone = new Hashtable<Integer, String>(); Hashtable<Integer, String> htable = new Hashtable<Integer, String>(); // put values into the table htable.put(1, "A"); htable.put(2, "B"); htable.put(3, "C"); htable.put(4, "from java2s.com"); // check table content System.out.println("Original hash table content: " + htable); // clone hash table htableclone = (Hashtable) htable.clone(); // check content after clone System.out.println("Clone table content: " + htableclone); }
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// www .j ava 2 s .c o m System.out.println(city + " is not located in the hashtable"); }
From source file:Main.java
public static void main(String args[]) { Hashtable<Integer, String> htable = new Hashtable<Integer, String>(); // put values into the table htable.put(1, "A"); htable.put(2, "B"); htable.put(3, "C"); htable.put(4, "from java2s.com"); // create a set view Set<Entry<Integer, String>> nset = htable.entrySet(); // display set result System.out.println("Set result:" + nset); }
From source file:Main.java
public static void main(String[] s) { Hashtable<String, String> table = new Hashtable<String, String>(); table.put("1", "Sunday"); table.put("2", "Monday"); table.put("3", "Tuesday"); table.put("4", "Wednesday"); table.put("5", "Thursday"); table.put("6", "Friday"); table.put("7", "Saturday"); System.out.println("Initial collection: " + table); Map m = Collections.unmodifiableMap(table); // m.put("key3", "value3"); }
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"); Set set = table.entrySet();/*from w ww . ja va 2s.co m*/ Iterator it = set.iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); System.out.println(entry.getKey() + " : " + entry.getValue()); } }