如何在Java中创建哈希表? [英] How do I create a hash table in Java?

查看:761
本文介绍了如何在Java中创建哈希表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中创建哈希表(或关联数组...)最直接的方法是什么?我的google-fu已经出现了一些例子,但有没有一个标准的方法来做到这一点?

What is the most straightforward way to create a hash table (or associative array...) in Java? My google-fu has turned up a couple examples, but is there a standard way to do this?

有没有一种方法来填充表的关键列表 - >值对,而不单独调用每个对的对象的add方法?

And is there a way to populate the table with a list of key->value pairs without individually calling an add method on the object for each pair?

推荐答案

Map map = new HashMap();
Hashtable ht = new Hashtable();

这两个类都可以从java.util包中找到。 2之间的区别在以下 jGuru FAQ条目中解释。

Both classes can be found from the java.util package. The difference between the 2 is explained in the following jGuru FAQ entry.

这篇关于如何在Java中创建哈希表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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