如何显示 Map<int[],Double> 中的键?
How to display keys from Map<int[],Double>?
我想将 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;
}
主要内容:
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);
我收到以下值(不是数组):
list of two keys: [[I@54bedef2, [I@5caf905d]
有人知道如何将其转换为数组吗?
for (int[] i : l1){
for(int j:i){
System.out.println(j);
}
}
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
你可以这样打印。
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);
}
}
}
问题是散列中的关键map.Please尝试使用以下代码
public static void main(String[] args) {
Map<Integer[], Double> mapVectFunc = new LinkedHashMap<Integer[], Double>();
Integer[] t1 = { 1, 0, 0, 1 };
Integer[] t2 = { 1, 1, 0, 0 };
Integer[] t3 = { 1, 0, 1, 1 };
mapVectFunc.put(t1, 26.0);
mapVectFunc.put(t2, 1.0);
mapVectFunc.put(t3, 6767.0);
ArrayList<Integer> ll = miZrodzicowIpotomstwa(mapVectFunc, 2);
System.out.printf("\n list of two keys: " + ll);
}
public static ArrayList<Integer> miZrodzicowIpotomstwa(Map<Integer[], Double> mapVectFunc_tmp, int x) {
ArrayList<Integer> klucz_t = new ArrayList<>();
for (Integer[] arr : mapVectFunc_tmp.keySet()) {
;
klucz_t.addAll(Arrays.asList(arr));
}
return klucz_t;
}
我想将 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;
}
主要内容:
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);
我收到以下值(不是数组):
list of two keys: [[I@54bedef2, [I@5caf905d]
有人知道如何将其转换为数组吗?
for (int[] i : l1){
for(int j:i){
System.out.println(j);
}
}
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
你可以这样打印。
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);
}
}
}
问题是散列中的关键map.Please尝试使用以下代码
public static void main(String[] args) {
Map<Integer[], Double> mapVectFunc = new LinkedHashMap<Integer[], Double>();
Integer[] t1 = { 1, 0, 0, 1 };
Integer[] t2 = { 1, 1, 0, 0 };
Integer[] t3 = { 1, 0, 1, 1 };
mapVectFunc.put(t1, 26.0);
mapVectFunc.put(t2, 1.0);
mapVectFunc.put(t3, 6767.0);
ArrayList<Integer> ll = miZrodzicowIpotomstwa(mapVectFunc, 2);
System.out.printf("\n list of two keys: " + ll);
}
public static ArrayList<Integer> miZrodzicowIpotomstwa(Map<Integer[], Double> mapVectFunc_tmp, int x) {
ArrayList<Integer> klucz_t = new ArrayList<>();
for (Integer[] arr : mapVectFunc_tmp.keySet()) {
;
klucz_t.addAll(Arrays.asList(arr));
}
return klucz_t;
}