【发布时间】:2020-05-27 04:52:33
【问题描述】:
我正在尝试将整数添加到 LinkedList;但是,我不确定如何将整数添加到已经存在的 LinkedList。
class HashChaining extends HashTable {
private ArrayList<LinkedList<Integer>> chains;
private HashFunction function;
HashChaining (Hashfunction function) {
this.function = function;
this.chains = new ArrayList<>(capacity);
for (int i=0; i<capacity; i++)
chains.add(i, new LinkedList<>());
}
void insert(int key) {
int location = function.apply(key);
chains.add(location, new LinkedList<Integer>(chains.get(location).push(key)));
}
【问题讨论】:
-
JDK
LinkedList没有push会返回列表。您不确定如何将元素添加到列表中是不正确的:您已经在构造函数中完成了一次。
标签: java list arraylist linked-list hashtable