Java 等价于 Python 字典 [英] Java Equivalent to Python Dictionaries

查看:30
本文介绍了Java 等价于 Python 字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 的长期用户,非常喜欢字典的使用方式.它们非常直观且易于使用.是否有一个很好的 Java 相当于 python 的字典?我听说有人使用哈希图和哈希表.有人能解释一下使用 hashtables 和 hashmaps 与 python 字典的异同吗?

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 的 dict 类是 Python 文档非正式地称为映射类型".在内部,dict 是使用哈希表实现的.

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

Java 的 HashMap 类是 Map 的实现 界面.在内部,HashMap 是使用哈希表实现的.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆