HashMap<String,List<Integer>> hm = new HashMap<String,List<Integer>>();
for (String s : text){
if (hm.containsKey(s)){
List<Integer> list = hm.get(s);
list.add(index);
hm.put(s, list);
}
else {
List<Integer> list = new ArrayList<Integer>();
list.add(index);
hm.put(s, list);
}
}
This
Map
的设计没有问题,如果不考虑效率,可以一行一行读,然后做相应操作啊。判断两行相等不就是用
equals
?Supplement:
Incomplete code:
According to what the questioner said, just use keyExist to determine whether it exists. I don’t know what other requirements the questioner needs;