| 38 | Objects.equals(id, ((CountedString)o).id); |
| 39 | } |
| 40 | public static void main(String[] args) { |
| 41 | Map<CountedString,Integer> map = new HashMap<>(); |
| 42 | CountedString[] cs = new CountedString[5]; |
| 43 | for(int i = 0; i < cs.length; i++) { |
| 44 | cs[i] = new CountedString("hi"); |
| 45 | map.put(cs[i], i); // Autobox int to Integer |
| 46 | } |
| 47 | System.out.println(map); |
| 48 | for(CountedString cstring : cs) { |
| 49 | System.out.println("Looking up " + cstring); |
| 50 | System.out.println(map.get(cstring)); |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | /* Output: |
| 55 | {String: hi id: 4 hashCode(): 146450=3, String: hi id: |