java 2维数组如何转换为HashMap

2024-11-19 04:25:02
推荐回答(3个)
回答1:

import java.util.HashMap;
import java.util.Map;

public class MyTest{
public static void main(String[] args){
String[] first={"1","2","3"};
String[] second = {"4","5","6"};
String[][] result = {first,second};
Map map = new HashMap();
for(int i=0;i for(int j=0;j map.put("str["+i+"]["+j+"]", result[i][j]);
}
System.out.println(map);
}
}

回答2:

遍历,然后一个一个换

回答3:

apache commons-lang ArrayUtils