小编jay*_*tel的帖子

如何将map.getValue()转换为ArrayList <Integer>()?

我想要做的是,将索引存储在当前元素重复的数组列表中,我已经完成了,现在我想检查一下。

HashMap<Integer,ArrayList<Integer>> hmap = new HashMap<>();
        for(int i=0;i<arr.length;i++)
        {
            if(!hmap.containsKey(arr[i]))
            {
                ArrayList<Integer> a1 = new ArrayList<>();
                hmap.put(arr[i],a1);
            }
            else
                hmap.get(arr[i]).add(i);
        }

        for(Map.Entry m:hmap.entrySet())
        {
            ArrayList<Integer> alist = {Here it is showing erorr.}m.getValue();
            System.out.println(m.getKey()+" ");
            for(int i=0;i<alist.size();i++) 
                System.out.print(alist.get(i)+" ");
        }
Run Code Online (Sandbox Code Playgroud)

java collections casting arraylist

0
推荐指数
1
解决办法
43
查看次数

标签 统计

arraylist ×1

casting ×1

collections ×1

java ×1