HashSet和HashMap之间的区别? [英] Difference between HashSet and HashMap?

查看:1143
本文介绍了HashSet和HashMap之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了 HashSet 不允许重复的值, HashMap Hashset

Apart from the fact that HashSet does not allow duplicate values, what is the difference between HashMap and Hashset?

我的意思是实现方式?

I mean implementation wise? It's a little bit vague because both use hash tables to store values.

推荐答案

它们是完全不同的结构体。 HashMap Map 的实现。 地图将键映射到值。

They are entirely different constructs. A HashMap is an implementation of Map. A Map maps keys to values. The key look up occurs using the hash.

另一方面, HashSet 设置旨在匹配数学模型的一套。如你所说, HashSet 确实使用 HashMap 来回退它的实现。

On the other hand, a HashSet is an implementation of Set. A Set is designed to match the mathematical model of a set. A HashSet does use a HashMap to back its implementation, as you noted. However, it implements an entirely different interface.

当你正在寻找最好的 Collection 目的,此教程是一个很好的开始。如果你真的想知道发生了什么,也有一本书

When you are looking for what will be the best Collection for your purposes, this Tutorial is a good starting place. If you truly want to know what's going on, there's a book for that, too.

这篇关于HashSet和HashMap之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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