且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java相当于Python字典

更新时间:2022-10-15 20:48:11

Python的 dict class是Python文档非正式地调用映射类型。在内部, dict 使用散列表实现。



Java的 HashMap 类是 地图 界面。在内部, HashMap 是使用散列表实现的。



语法有一些细微差异,我相信实施方式略有不同,但总体而言它们是完全可互换的。


I am a long time user of Python and really like the way that the dictionaries are used. They are very intuitive and easy to use. Is there a good Java equivalent to python's dictionaries? I have heard of people using hashmaps and hashtables. Could someone explain the similarities and differences of using hashtables and hashmaps versus python's dictionaries?

Python's dict class is an implementation of what the Python documentation informally calls "mapping types". Internally, dict is implemented using a hashtable.

Java's HashMap class is an implementation of the Map interface. Internally, HashMap is implemented using a hashtable.

There are a few minor differences in syntax, and I believe the implementations are tuned slightly differently, but overall they are completely interchangeable.