Pattern p=Pattern.compile("[a-zA-Z0-9]+"); Matcher w=p.matcher(str); while(w.find()){ String word=w.group(); int index=w.start(); if(!dictionary.containsKey(word)){ ArrayList<Location> list=new ArrayList<Location>(); dictionary.put(word, list); } ArrayList<Location> list=dictionary.get(word); Location pair=new Location(row,index); list.add(pair); dictionary.put(word, list); //System.out.println(index); }
时间: 2024-10-10 08:02:11