Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 使用ArrayList数组创建类似地图的结构_Arrays_List_Map_Count_Word - Fatal编程技术网

Arrays 使用ArrayList数组创建类似地图的结构

Arrays 使用ArrayList数组创建类似地图的结构,arrays,list,map,count,word,Arrays,List,Map,Count,Word,我需要使用数组或ArrayList创建一个类似于地图的数据结构 快速程序浏览:我的地图保存Word的对象,它是一个字符串,并保存Word在下一个文件中出现的频率计数 这是MyMap的代码,程序什么也不输出 List<Word>[] table; int tableSize; int index; public MyMap(int tableSize){ table = new ArrayList[tableSize]; this.tableSize = tableS

我需要使用数组或ArrayList创建一个类似于地图的数据结构

快速程序浏览:我的地图保存Word的对象,它是一个字符串,并保存Word在下一个文件中出现的频率计数

这是MyMap的代码,程序什么也不输出

List<Word>[] table;
int tableSize;
int index;

public MyMap(int tableSize){
    table = new ArrayList[tableSize];
    this.tableSize = tableSize;
}

//Problem!!
public void put(Word w){
    index = Math.abs(w.hashCode()) % tableSize;
    if(table[index].isEmpty()){
        table[index].add(w);
    }
    else{ 
        w.increaseFreq();
        table[index].set(index, w);
    }

}

public void displayMap(){
    for(List<Word> w: table){
        System.out.println(w);
    }
}
List[]表;
int表大小;
整数指数;
公共MyMap(int表大小){
table=newarraylist[tableSize];
this.tableSize=表大小;
}
//问题!!
公开作废认沽权证(w字){
index=Math.abs(w.hashCode())%tableSize;
if(表[index].isEmpty()){
表[索引]。添加(w);
}
否则{
w、 增加频率();
表[index].set(index,w);
}
}
公共void displayMap(){
用于(列表w:表格){
系统输出打印LN(w);
}
}

}

使用通用词典或词典怎么样?
如果使用KeyedCollection,则需要从中继承并提供GetKeyForItem实现