显然ArrayList.getValue().size()
不是正确的答案。
我环顾四周,对谷歌来说不是一个简单的问题。
我已经非常全面地解释了我在伪代码注释中尝试做什么,也许有人知道如何迭代该数组列表?
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的第一个答案,以防您感兴趣。
答案 0 :(得分:2)
迭代地图的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
{
}
}
}