List of usage examples for java.util Hashtable put
public synchronized V put(K key, V value)
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"); Hashtable<Integer, String> htable1 = new Hashtable<Integer, String>(htable); }
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();// w w w .ja v a 2 s .c om System.out.println("Display result: " + st); }
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[]) { // 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);/*from w ww .j a v a 2s .c om*/ System.out.println("Hash table value after remove: " + 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"); // check if table contains "C" boolean isavailable = htable.contains("C"); // display search result System.out.println("Hash table contains 'C': " + isavailable); }
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"); // check if table contains key "3" boolean isavailable = htable.containsKey(3); // display search result System.out.println("Hash table contains key '3': " + isavailable); }
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"); // check if table contains value "C" boolean isavailable = htable.containsValue("C"); // display search result System.out.println("Hash table contains value 'C': " + isavailable); }
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 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 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()); }//w w w . j a v a 2 s .c o m }