-
Notifications
You must be signed in to change notification settings - Fork 0
/
Collections12.java
61 lines (47 loc) · 1.25 KB
/
Collections12.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
public class Employee
{
private Integer id;
private String name;
private String city;
public Employee(Integer id, String name, String city) {
this.id = id;
this.name = name;
this.city = city;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Override
public String toString() {
return "Employee{" +
"name='" + name + '\'' +
", city='" + city + '\'' +
'}';
}
}
import java.util.*;
public class HashMapUserDefinedObjectExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
Map<Integer, Employee> employeesMap = new HashMap<>();
employeesMap.put(1001, new Employee(1001, "Rajeev", "Bengaluru"));
employeesMap.put(1002, new Employee(1002, "David", "New York"));
employeesMap.put(1003, new Employee(1003, "Jack", "Paris"));
System.out.println(employeesMap);
}
}