gpt4 book ai didi

java - 确定 hashmap 内部数组列表的大小

转载 作者:行者123 更新时间:2023-12-02 04:58:09 25 4
gpt4 key购买 nike

显然ArrayList.getValue().size()不是正确的答案。

我环顾四周,发现向 Google 提出这个问题并不容易。

我已经在伪代码注释中非常全面地解释了我想要做什么,也许有人知道如何迭代该数组列表?

public static void perceptron_data_struc_generateur(Set<String> GLOBO_DICT, 
Map<File, ArrayList<String> > fileDict,
Map<File, int[] > perceptron_input)
{

//create a new entry in the array list 'perceptron_input'
//with the key as the file name from fileDict
//create a new array which is the length of GLOBO_DICT
//iterate through the indicies of GLOBO_DICT
//for all words in globo dict, if that word appears in fileDict,
//increment the perceptron_input index that corresponds to that
//word in GLOBO_DICT by the number of times that word appears in fileDict

for (Map.Entry entry : fileDict.entrySet())
{
//System.out.println(entry.getKey());
int[] cross_czech = new int[GLOBO_DICT.size()];

for (String s : GLOBO_DICT)
{
for(int i = 0; i < entry.getValue() ).size(); i++)
{

}
}

}
}

最终目标是获得 this question 的第一个答案,如果你有兴趣的话。

最佳答案

迭代 map 的 ArrayList 值:

for (Map.Entry<File, ArrayList<String>> entry : fileDict.entrySet()) 
{
int[] cross_czech = new int[GLOBO_DICT.size()];

for (String s : GLOBO_DICT)
{
for(String st : entry.getValue()) // iterates over all the Strings
// of the ArrayList of the
// current entry
{

}
}

}

关于java - 确定 hashmap 内部数组列表的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28556698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com