suppose need implement hashtable on own,but have problems implementing constructor. example,if need initialize list[] buckets,but when write following codes,the computer gave wrong signal of"buckets[i]=new list()" , can tell me how finish constructor in case? import java.util.list;
import java.util.linkedlist; public class generalhashmap extends myhashmap { public list< string>[] buckets; public generalhashmap() { for(int i=0;i<120;i++) { buckets[i]=new list<string>(); } // todo: implement constructor } public generalhashmap(int newsize) { for(int i=0;i<newsize;i++) { buckets[i]=new list<string>(); } } @override protected int hash(string token) { // todo: implement hashing function general hashmap return -1; } @override public void add(string token) { // todo: implement add method using buckets } @override public void display() { // todo: implement display method show contents of buckets } }
in java list interface cannot instantiated. need class implementing such interface, example, arraylist. try
buckets = new list[120]; for(int i=0;i<120;i++) { buckets[i]=new arraylist<string>(); }