Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Hashtable ht = new Hashtable();
- //you add elements to Hashtable using put method
- //put(key, value)
- ht.put("Java", new Double[]{1.2, 2.4, 3.3});
- ht.put(".NET", new Double[]{1.2, 2.5, 5.6});
- ht.put("Javascript", new Double[]{1.2, 2.4, 3.1});
- ht.put("HTML", new Double[]{1.2, 2.4, 7.6});
- //looping through all the elements in hashtable
- // String str;
- // //you can retrieve all the keys in hashtable using .keys() method
- // Enumeration names = ht.keys();
- // while (names.hasMoreElements()) {
- // //next element retrieves the next element in the dictionary
- // str = (String) names.nextElement();
- // //.get(key) returns the value of the key stored in the hashtable
- // System.out.println(str + ": " + ht.get(str) + newLine);
- // }
- Set<String> keys = ht.keySet();
- for(String key: keys){
- System.out.println("key: "+key+"\nvalue: "+ht.get(key));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment