我有一个HashMap声明为
static HashMap<String,ArrayList<Integer>> inverted_index = new HashMap<String,ArrayList<Integer>>();
Run Code Online (Sandbox Code Playgroud)
我重复了它的键
public static void printInvertedIndex() throws FileNotFoundException{
PrintWriter writer = new PrintWriter(new File("InvertedIndex.txt"));
Iterator it = inverted_index.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry)it.next();
writer.println(pair.getKey() + " " + pair.getValue());
it.remove();
}
writer.close();
}
Run Code Online (Sandbox Code Playgroud)
我在一个名为printInvertedIndex()的函数中完成了所有这些操作.现在在其他一些函数中我想再次迭代HashMap,所以我做了这个
public static void createPermutermIndex(){
permuterm_index.clear();
Iterator it = inverted_index.entrySet().iterator();
while (it.hasNext()) {
System.out.println("here");
Map.Entry pair = (Map.Entry)it.next();
String temp;
temp = pair.getKey() + "$";
ArrayList<String> perms = rotations(temp);
System.out.println(perms.size());
for(int i=0; i<perms.size(); i++)
System.out.println(perms.get(i));
//permuterm_index.put(temp, perms.get(i));
it.remove();
} …Run Code Online (Sandbox Code Playgroud)