Java中的Map是一个接口,它不能直接实例化。但是可以通过它的实现类HashMap、TreeMap等来创建Map对象。
Map<String, Integer> map = new HashMap<>();
Map<String, Integer> map = new TreeMap<>();
Map<String, Integer> map = new Hashtable<>();
Map<String, Integer> map = new LinkedHashMap<>();
以上示例中的String
表示键的类型,Integer
表示值的类型。根据实际需求选择合适的实现类来构造Map对象。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:java怎么初始化map大小