【发布时间】:2012-01-13 12:40:27
【问题描述】:
我的目录中有文本文件。我需要做的是;
---对于所有文件中的每个单词
---查找文件中每个单词的位置索引
---查找单词通过的每个文件
为了做到这一点;
HashMap<String, HashMap<Integer, ArrayList<Integer>>>
我想使用上述结构。
String word;
String pattern = "[[^\\w\\süÜıİöÖşŞğĞçÇ]\\d]+";
while ((word = infile.readLine()) != null) {
String[] wordList = word.replaceAll(pattern, " ").split("\\s+");
for (int j = 0; j < wordList.length; j++) {
if(!wordList[j].isEmpty()){
if(!refinedDict.containsKey(wordList[j])){
refinedDict.put(wordList[j], 1);
}
else{
refinedDict.put(wordList[j], refinedDict.get(wordList[j])+1);
}
}//end of for
}//end if
else{
//do something
}
}//end for
}//end while
Set<String> keys=refinedDict.keySet();
List<String> list=sortList(keys);
Iterator<String> it=list.iterator();
while(it.hasNext()){
String key=it.next();
outfile.write(key + "\t" + refinedDict.get(key) + "\n");
如何在 HashMap 中使用 HashMap 中的 ArrayList
编辑
应用toto2的解决方案实施工作后。但是,为了将其写入文件 --->
word[fileId{positions}, fileId{positions}...]
可以做什么?
实现可序列化对于这样的设计没有用处。
【问题讨论】:
标签: java text arraylist hashmap