java - 如何正确使用HashMap?

标签 java data-structures map hashmap key-value

HashMap savedStuff = new HashMap();
savedStuff.put("symbol", this.symbol); //this is a string
savedStuff.put("index", this.index); //this is an int

给我警告:

HashMap is a raw type. References to generic type HashMap<K,V> should be parameterized  

最佳答案

HashMap<String, Object> savedStuff = new HashMap<String, Object>();

当然,在提取元素时您仍然需要注意使用正确的类型。

关于java - 如何正确使用HashMap?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3640648/

相关文章:

database - 关于构建快速分布式数据库的建议

data-structures - 堆和红黑树有什么区别?

map - Go:什么决定了映射键的迭代顺序?

C++在 vector 中找到相同的记录

java - 将更新发布到 "a"墙

java - 如何确保所有生成的线程都已完成以便处理可以继续?

java - 'android.annotation.NonNull' 在 'android.annotation' 中不公开。无法从外部包访问

c++ - 我应该通过指针还是通过更新记录来操作 C++ 映射的值?

java - 推土机升级到mapstruct

java - Spring Data JPA 需要 Eclipse 链接和 Hibernate?