Java相当于Python字典 [英] Java Equivalent to Python Dictionaries
问题描述
Python的 dict
class是Python文档非正式地调用映射类型。在内部, dict
使用散列表实现。
Java的 HashMap
类是< a href =http://java.sun.com/javase/6/docs/api/java/util/Map.html =noreferrer> 地图
界面。在内部, 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.
这篇关于Java相当于Python字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!