Java 将数字添加到ArrayList中的LinkedList中
我试图在LinkedList中添加一个整数;但是,我不知道如何将整数添加到已经存在的LinkedList中Java 将数字添加到ArrayList中的LinkedList中,java,list,arraylist,linked-list,hashtable,Java,List,Arraylist,Linked List,Hashtable,我试图在LinkedList中添加一个整数;但是,我不知道如何将整数添加到已经存在的LinkedList中 class HashChaining extends HashTable { private ArrayList<LinkedList<Integer>> chains; private HashFunction function; HashChaining (Hashfunction function) { this.function =
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)));
}
类哈希链扩展了哈希表{
私有ArrayList链;
私有哈希函数;
HashChaining(Hashfunction){
这个函数=函数;
this.chains=新阵列列表(容量);
对于(inti=0;i如果你看一下,你会发现,一个方法add(int-index,E-element)
在给定索引处插入元素。您要实现的是将元素添加到内部列表中:
chains.get(location).add(key)
chains.get(位置)
将在位置
给定的位置上检索内部链接列表
,然后在此列表中,您可以添加元素。JDK链接列表
没有返回列表的推送
。您不确定如何将元素添加到列表中并不是真的:您已经在构造中这样做过一次了或