Java相当于Python字典 [英] Java Equivalent to Python Dictionaries

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

问题描述

我是Python的长时间用户,真的很喜欢使用字典的方式。它们非常直观,易于使用。是否有一个很好的Java相当于python的字典?听说有人使用hashmaps和hashtables。有人可以解释使用哈希表和hashmaps与python的字典的相似之处吗?

解决方案

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

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