問題:
I have a following method...which actually takes the list of sentences and splits each sentence into words.我有一個下面的方法......它實際上需要句子列表並將每個句子分成單詞。 Here is it:就這個:
public List<String> getWords(List<String> strSentences){
allWords = new ArrayList<String>();
Iterator<String> itrTemp = strSentences.iterator();
while(itrTemp.hasNext()){
String strTemp = itrTemp.next();
allWords = Arrays.asList(strTemp.toLowerCase().split("\\s+"));
}
return allWords;
}
I have to pass this list into a hashmap in a following format我必須按照以下格式將此列表傳遞到哈希圖中
HashMap<String, ArrayList<String>>
so this method returns List and I need a arrayList?所以這個方法返回List,我需要一個arrayList? If I try to cast it doesn't workout... any suggestions?如果我嘗試投射它不會鍛鍊...有什麼建議嗎?
Also, if I change the ArrayList to List in a HashMap, I get另外,如果我將 ArrayList 更改爲 HashMap 中的 List,我會得到
java.lang.UnsupportedOperationException
because of this line in my code因爲我的代碼中有這一行
sentenceList.add(((Element)sentenceNodeList.item(sentenceIndex)).getTextContent());
Any better suggestions?有什麼更好的建議嗎?