1 import java.util.HashSet;
2 import java.util.Set;
3
4 /**
5 This program prints hash codes of countries.
6 */
7 public class HashCodePrinter
8 {
9 public static void main(String[] args)
10 {
11 Country country1 = new Country("Belgium", 30510);
12 Country country2 = new Country("Thailand", 514000);
13 Country country3 = new Country("Belgium", 30510);
14
15 System.out.println("hash code of country1=" + country1.hashCode());
16 System.out.println("hash code of country2=" + country2.hashCode());
17 System.out.println("hash code of country3=" + country3.hashCode());
18
19 // Add the countries to the hash set.
20
21 Set<Country> countries = new HashSet<Country>();
22 countries.add(country1);
23 countries.add(country2);
24 countries.add(country3);
25
26 // Print the set. Note that the set has two elements.
27
28 System.out.println(countries);
29 }
30 }