- package map;
- import java.util.HashMap;
- import java.util.Map;
- public class MapText
- {
- public static void main(String[] args)
- {
- Map<String, Emp> map = new HashMap<String, Emp>();
- Emp emp = new Emp(001, "张三");
- Emp emp2 = new Emp(005, "李四");
- Emp emp3 = new Emp(004, "王一");
- map.put("001", emp);
- map.put("005", emp2);
- map.put("004", emp3);
- System.out.println(map);
- }
- }
- class Emp
- {
- private int E_id;
- private String E_name;
- public Emp(int e_id, String e_name)
- {
- E_id = e_id;
- E_name = e_name;
- }
- public int getE_id()
- {
- return E_id;
- }
- public void setE_id(int e_id)
- {
- E_id = e_id;
- }
- public String getE_name()
- {
- return E_name;
- }
- public void setE_name(String e_name)
- {
- E_name = e_name;
- }
- @Override
- public String toString()
- {
- return "Emp [E_id=" + E_id + ", E_name=" + E_name + "]";
- }
- }
复制代码 |