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) {

    Dictionary d = new Hashtable();

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

    // print how many times put was called
    System.out.println("Number of times put was called:" + d.size());
}

From source file:Main.java

public static void main(String[] args) {
    Dictionary d = new Hashtable();

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

    // return an enumeration of the keys from this dictionary.
    for (Enumeration e = d.keys(); e.hasMoreElements();) {
        System.out.println(e.nextElement());
    }/*  w  w  w .  j  av  a 2s  .co  m*/
}

From source file:Main.java

public static void main(String[] args) {

    Dictionary d = new Hashtable();

    // add elements in the hashtable
    d.put("1", "from java2s.com");
    d.put("2", "Cocoa");
    d.put("5", "Coffee");

    // return true if this dictionary maps no keys to value.
    boolean b = d.isEmpty();
    System.out.println("Dictionary is empty:" + b);
}

From source file:Main.java

public static void main(String[] args) {

    Dictionary d = new Hashtable();

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

    // remove one element
    System.out.println(d.get("5"));
    System.out.println(d.remove("5") + " has been removed");
    System.out.println(d.get("5"));
}

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

    System.out.println(table.containsKey("key3"));

}

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

    System.out.println(table.contains("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");

    System.out.println(table.isEmpty());
    System.out.println(table.size());
}

From source file:Main.java

public static void main(String[] args) {

    Dictionary d = new Hashtable();

    // add 2 elements
    d.put(1, "Cocoa");
    d.put(4, "from java2s.com" + "Bar");
    System.out.println("1 is " + d.get(1));
    System.out.println("4 is " + d.get(4));

    // generates a series of elements, one at a time
    for (Enumeration e = d.elements(); e.hasMoreElements();) {
        System.out.println(e.nextElement());
    }/* w w  w  .  ja va2s .c o  m*/
}

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

    table.remove("key1");

    System.out.println(table);/*from w w  w  . j a va 2 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");

    table.clear();//  w  ww. jav a2  s  .co m

    System.out.println(table);
}