-1
我已將單詞文件轉換爲字符串數組。我需要以某種方式將數組轉換爲字長列表並使其可搜索。換句話說,我需要能夠輸入一個單詞長度(比如5),並且只能顯示單詞長度爲5的單詞。幫幫我?詞典詞典:需要掃描每個元素的詞長度並使其可搜索
public static void main(String[] args) throws IOException {
String token1 = "";
Scanner scan = new Scanner(new File("No.txt"));
List<String> temps = new ArrayList<String>();
while (scan.hasNext()){
token1 = scan.next();
temps.add(token1);
}
scan.close();
String[] tempsArray = temps.toArray(new String[0]);
for (String s : tempsArray) {
循環遍歷數組,比較長? – tnw
查看[Google Guava的'Multimap'](https://github.com/google/guava/wiki/NewCollectionTypesExplained#multimap),例如你可以使用'Multimap'來收集單詞的長度。 –
Thomas
對我的回答有任何意見/反饋?它有幫助嗎?我可以添加一些東西以便讓你接受嗎? – GhostCat