Java: Composite key in hashmaps
问题 I would like to store a group of objects in a hashmap , where the key shall be a composite of two string values. is there a way to achieve this? i can simply concatenate the two strings , but im sure there is a better way to do this. 回答1: You could have a custom object containing the two strings: class StringKey { private String str1; private String str2; } Problem is, you need to determine the equality test and the hash code for two such objects. Equality could be the match on both strings