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);
}
}
这个
Map
的设计没有问题,如果不考虑效率,可以一行一行读,然后做相应操作啊。判断两行相等不就是用
equals
吗?补充:
不完全代码:
按照题主的说法,就使用keyExist来判断是否存在就可以了阿,不知道题主是需要有什么其他的要求;