map套map就是将前一个map中的数据填充到map中(必须保证两个集合中的泛型一致)
public static void main(String[] args) { HashMap<String, String> hashMap = new HashMap<>(); hashMap.put("1", "11"); hashMap.put("3","33"); HashMap<String, String> hashMap1 = new HashMap<>(hashMap); hashMap1.put("2", "22"); hashMap1.put("4","44"); for (Map.Entry<String, String> entry : hashMap1.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); System.out.println(key + ":" + value); } }
返回结果:
1:11 2:22 3:33 4:44
同理list1集合中套list2就是将list1中的元素复制到list2集合中