0

The class Hashtable<K,V> sets a self-implemrnted Hashtable as a list in the constructor. How can I instanziate all the needed Lists for additional Values per key right in the Constructor, so that all Table-Elements have their own List? (The size of the table can vary)

public class  Hashtable<K, V> {
    public Hashtable(int size, int[] a) { // a: mathematical vector, represented as int[] for hash-function
       table = (List<Pair<K, V>>[]) new List[size];
       ...
    }
       ...
}
HeapUnderStop
  • 378
  • 1
  • 9
  • [`Hashtable`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/Hashtable.html) is a legacy class whose Javadoc recommends using `HashMap` or `ConcurrentHashMap` instead. `Vector` is a legacy class in Java, not a synonym for an array. And an array in Java should not be referred to as a list; this causes confusion with the [`List`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html) interface bundled with Java. I suggest you edit the title and body of your question to fix these terms. – Basil Bourque May 29 '22 at 21:06
  • 1
    It's very unclear if you're making your own hash table class or using an existing one. – Louis Wasserman May 29 '22 at 21:31
  • Possibly a duplicate of [*How to have multimap functionality in Java?*](https://stackoverflow.com/q/31545314/642706). – Basil Bourque May 29 '22 at 22:04

0 Answers0