Example usage for java.util Hashtable Hashtable

List of usage examples for java.util Hashtable Hashtable

Introduction

In this page you can find the example usage for java.util Hashtable Hashtable.

Prototype

public Hashtable() 

Source Link

Document

Constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75).

Usage

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[]) {
    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 a new hasthtable
    Dictionary d = new Hashtable();

    // Put some elements
    d.put("1", "from java2s.com");
    d.put("2", "Cocoa");
    d.put("5", "Coffee");

    // print the size of the dictionary
    System.out.println("Size of dictionary:" + d.size());
    ;/*from   w  ww . ja  va 2  s.com*/
}

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 table content
    System.out.println("Hash table content: " + htable);

    // clear the table
    htable.clear();/*from www  .  jav a 2s .com*/

    // check content after clear
    System.out.println("Hash table content after clear: " + htable);
}

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));
    }//ww  w .ja v  a2  s. c om
}

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));
    }/*from w  w  w .  jav a2s .co m*/

    System.out.println(table.values());
}

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");

    Enumeration e = ht.elements();

    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }/*w w w.j  av a2  s .c  o  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");

    Enumeration e = ht.keys();// w  ww .  j a va  2s . c o  m

    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }
}