Your add() method return boolean and can't be used in your example. And you need to create a data structure HashSet. For example:
private static HashMap<Integer, HashSet<exampleObject>> test = new HashMap<>();
private static HashSet<exampleObject> hashSet = new HashSet<>();
public static void main(String[] args) {
hashSet.add(new exampleObject("key", "value")); // <-- returns boolean
test.put(1, hashSet);
for (exampleObject element : test.get(1)) {
System.out.println(element);
}
}
P.S. exampleObject have 2 String fields here. And don't forget to override equals() and hashCode() in exampleObject for the correct output of the object to print.
发布评论
评论(1)
您的add()方法返回布尔值,在您的示例中无法使用。
您需要创建数据结构标签。
例如:
PS示例Object在此处有2个字符串字段。而且,不要忘记在示例视频中覆盖equals()和hashcode(),以打印对象的正确输出。
Your add() method return boolean and can't be used in your example.
And you need to create a data structure HashSet.
For example:
P.S. exampleObject have 2 String fields here. And don't forget to override equals() and hashCode() in exampleObject for the correct output of the object to print.