【问题标题】:determine size of hash map internal array list确定 hashmap 内部数组列表的大小
【发布时间】:2015-02-17 07:23:36
【问题描述】:

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

我环顾四周,向 Google 提出的问题并不容易。

我已经非常全面地解释了我在伪代码 cmets 中尝试做什么,也许有人知道如何遍历该数组列表?

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 的第一个答案,以防您有兴趣。

【问题讨论】:

    标签: java


    【解决方案1】:

    遍历地图的 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
            {
    
            }
        }
    
    }
    

    【讨论】:

    • 你知道我如何构建内部组件,以便复制链接问题中描述的数据结构,即this one
    • 如何获取 GLOBO_DICT 的索引来代替 's'?
    • @flavius_valens index of GLOBO_DICT 是什么意思? GLOBO_DICT 是一个集合,所以元素没有索引。
    • 我刚刚尝试使用this wierd method,但是...没有用,我编辑了答案以向您展示我是如何做到的。顺便说一句,这是失礼吗?
    • 也许将集合转换为列表?
    猜你喜欢
    • 2017-08-13
    • 2020-09-29
    • 2020-01-31
    • 1970-01-01
    • 2016-12-13
    • 2020-12-09
    • 2017-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多