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(int initialCapacity, float loadFactor) 

Source Link

Document

Constructs a new, empty hashtable with the specified initial capacity and the specified load factor.

Usage

From source file:Main.java

public static void main(String args[]) {

    Hashtable<Integer, String> htable = new Hashtable<Integer, String>(10, 0.75F);

    // 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();//  w w  w  .j av a  2  s .  co m

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

From source file:Main.java

public static <K, V> Hashtable<K, V> newHashtable(final int initialCapacity, final float loadFactor) {
    return new Hashtable<K, V>(initialCapacity, loadFactor);
}

From source file:BucketizedHashtable.java

/**
 * Constructs a new, empty BucketizedHashtable with the specified bucket
 * size, initial capacity and load factor.
 * @param bucketSize the number of buckets used for hashing
 * @param initialCapacity the initial capacity of BucketizedHashtable
 * @param loadFactor the load factor of hashtable
 *//*from  www  . java  2  s. c om*/
public BucketizedHashtable(int bucketSize, int initialCapacity, float loadFactor) {
    if (bucketSize <= 0 || initialCapacity < 0) {
        throw new IllegalArgumentException();
    }

    this.bucketSize = bucketSize;

    hashtables = new Hashtable[bucketSize];

    // always round up to the nearest integer so that it has at
    // least the initialCapacity
    int initialHashtableSize = (int) Math.ceil((double) initialCapacity / bucketSize);

    for (int i = 0; i < bucketSize; i++) {
        hashtables[i] = new Hashtable(initialHashtableSize, loadFactor);
    }
}

From source file:com.github.r351574nc3.amex.assignment1.csv.DefaultInterpreter.java

/**
 * Convert records to {@link TestData}.//from   w  ww . j a v  a  2  s . c  o  m
 *
 * @return {@link Hashtable} instance which makes record lookup by name much easier. Records that belong to a given name are indexed
 * within the {@link Hashtable} instance. In case there is more than one instance, the object in the {@link Hashtable} is
 * a {@link LinkedList} which can be quickly iterated
 */
public Hashtable interpret(final File input) throws IOException {
    final CSVParser parser = CSVParser.parse(input, Charset.defaultCharset(),
            CSVFormat.RFC4180.withDelimiter('|'));

    // Using a {@link Hashtable with the name field on the CSV record as the key. A lower load factor is used to give more
    // priority to the time cost for looking up values. 
    final Hashtable<String, LinkedList<TestData>> index = new Hashtable<String, LinkedList<TestData>>(2, 0.5f);

    for (final CSVRecord record : parser) {
        final EmailNotificationTestData data = toTestData(record);

        LinkedList<TestData> data_ls = index.get(data.getName());
        if (data_ls == null) {
            data_ls = new LinkedList<TestData>();
            index.put(data.getName(), data_ls);
        }
        data_ls.add(data);
    }

    return index;
}