如何从Map <int [],double>显示键?

时间:2017-05-22 16:31:26

标签: java arraylist linkedhashmap

我想将有序地图中的x个元素(只是键)添加到列表中并显示它们。

public static ArrayList<int[]> miZrodzicowIpotomstwa(Map<int[],Double> mapVectFunc_tmp, int x)
{
    ArrayList<int[]> listaMi = new ArrayList<>();
    ArrayList<int[]> klucz_t = new ArrayList<>(mapVectFunc_tmp.keySet());

    for(int i=0; i<x; i++)
    {
        listaMi.add(klucz_t.get(i));
    }
    return listaMi;
}

在main中:

Map<int[],Double> mapVectFunc = new LinkedHashMap<int[],Double>();
int []t1={1,0,0,1};
int []t2={1,1,0,0};
int []t3={1,0,1,1};
mapVectFunc.put(t1,26.0);
mapVectFunc.put(t2,1.0);
mapVectFunc.put(t3,6767.0);
ArrayList<int[]> ll= miZrodzicowIpotomstwa(mapVectFunc, 2);
System.out.printf("\n list of two keys: "+ll);

我收到了以下值(不是数组):

  

两个键的列表:[[I @ 54bedef2,[I @ 5caf905d]

有人知道如何将其转换为数组吗?

4 个答案:

答案 0 :(得分:0)

for (int[] i : l1){
    for(int j:i){
        System.out.println(j);
    }
}

答案 1 :(得分:0)

ArrayList<int[]> ll= miZrodzicowIpotomstwa(mapVectFunc, 2);
...
System.out.println("\n list of two keys: ");
for (int[] i: ll.keySet()){

            String key =i.toString();
            String value = ll.get(i).toString();  
            System.out.println(key + " " + value);  
}

这里多一点: Printing HashMap In Java

答案 2 :(得分:0)

你可以像这样打印出来。

public static void main(String[] args) {
    Map<int[], Double> mapVectFunc = new LinkedHashMap<int[], Double>();
    int[] t1 = { 1, 0, 0, 1 };
    int[] t2 = { 1, 1, 0, 0 };
    int[] t3 = { 1, 0, 1, 1 };
    mapVectFunc.put(t1, 26.0);
    mapVectFunc.put(t2, 1.0);
    mapVectFunc.put(t3, 6767.0);
    ArrayList<int[]> ll = miZrodzicowIpotomstwa(mapVectFunc, 2);

    int c = 0;
    for (int[] i : ll) {
        System.out.println("Array" + c++);
        for (int j : i) {
            System.out.println(j);
        }
    }   
}

答案 3 :(得分:0)

问题是哈希映射的关键。请尝试使用以下代码

func
相关问题