public static List<Map> returnMapList(){
Map<String,Integer> map = new HashMap<>();
map.put("age",1);
map.put("high",30);
Map<String,int[]> map1 = new HashMap<>();
map1.put("array", new int[]{1, 2});
List<Map> listMap = new ArrayList<Map>();
listMap.add(map);
listMap.add(map1);
return listMap;
}
public static void main(String[] args){
List<int[]> list1 = returnList();
System.out.println(Arrays.toString(list1.get(0)) + Arrays.toString(list1.get(1)) + Arrays.toString(list1.get(2)) + "\nreturnlist结束\n");
Map<String,Integer> mapTest = returnMap();
System.out.println("age = " + mapTest.get("age") +", high = " + mapTest.get("high") + "\nreturnMap结束\n");
List<Map> list2 = returnMapList();
System.out.println(list2.get(0) +" , " + list2.get(1) + "\nreturnMapList结束");
System.out.print("调用返回的int和int[]:");
Map map0 = list2.get(0);
Map map1 = list2.get(1);
System.out.println( "age = " + map0.get("age") );
System.out.println("array = " + Arrays.toString((int[]) map1.get("array")));
}
帮助博主链接