列表<String>到 ArrayList<String> 轉換問題 - List<String> to ArrayList<String> conversion issue

問題:

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?有什麼更好的建議嗎?


解決方案:

參考: https://stackoom.com/en/question/t70Z
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章