6
List <String>到ArrayList <String>的转换问题
我有以下方法...实际上是采用句子列表并将每个句子拆分为单词。就这个: 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; } 我必须将此列表以以下格式传递到哈希图中 HashMap<String, ArrayList<String>> 所以这个方法返回List,我需要一个arrayList吗?如果我尝试投射,那将不起作用...有什么建议吗? 另外,如果我将HashMap中的ArrayList更改为List,我会得到 java.lang.UnsupportedOperationException 因为我的代码中有这一行 sentenceList.add(((Element)sentenceNodeList.item(sentenceIndex)).getTextContent()); 还有更好的建议吗?