Bootstrap

Map集合 entrySet() ,keySet(), values()

package com.li.springboot.text;

import java.util.*;

@SuppressWarnings({"all"})
public class Text {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("num1", new Dog("大黄", 2));
        map.put("num2", new Dog("小黄", 2));
        map.put("num3", new Dog("乐乐", 3));
        //KeySet()
        Set set = map.keySet();
        System.out.println(set.getClass());//class java.util.HashMap$KeySet
        //values()
        Collection values = map.values();
        System.out.println(values.getClass());//class java.util.HashMap$Values
        //entrySet()
        Set entrySet = map.entrySet();
        for (Object o : entrySet) {
            Map.Entry entry = (Map.Entry) o;
            System.out.println(entry.getKey() + "\t" + entry.getValue());
        }
    }
}

class Dog {
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

;