Map
HashMap 无序的,key =value 形式的。
public class MapDemo {
public static void main(String[] args) {
Map<String,Integer> map = new HashMap<>();
map.put("aa",11);
map.put("bb",12);
map.put("cc",13);
System.out.println(map);
Set<String> keySet = map.keySet();
System.out.println(keySet);
Collection<Integer> values = map.values();
System.out.println(values);
Set<Map.Entry<String, Integer>> entries = map.entrySet();
System.out.println(entries);
}
}
map.keySet() 将所有的 key作为一个set集合
Set<Map.Entry<String, Integer>> entries = map.entrySet();
map.entrySet()
将每一对key value 作为一个 Entry类
将所有的 Entry类,组成一个Set集合。