简体   繁体   English

如何从没有哈希表键的哈希表中收集所有值

[英]How to collect all values from hashtable without its keys

i have a merged hash table and it is having around 4351 distinct keys and its relevant values,but i don't want to specify its each and every key for fetching values,i want to directly collect all the values only, how do i handle this? 我有一个合并的哈希表,它具有大约4351个不同的键及其相关值,但是我不想指定其每个键来获取值,我只想直接收集所有值,我该如何处理这个?

Note:all the values are distinct 100% ,thats why i want to fetch blindly those data for further process 注意:所有值都是100%的不同值,这就是为什么我想盲目获取那些数据以进行进一步处理

Take a look at Hashtable#values() : 看看Hashtable#values()

public Collection<V> values()

Returns a Collection view of the values contained in this map. 返回此映射中包含的值的Collection视图。 The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. 集合由地图支持,因此对地图的更改会反映在集合中,反之亦然。 If the map is modified while an iteration over the collection is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. 如果在对集合进行迭代时修改了映射(通过迭代器自己的remove操作除外),则迭代的结果是不确定的。 The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. 集合支持元素删除,该元素通过Iterator.remove,Collection.remove,removeAll,retainAll和clear操作从映射中删除相应的映射。 It does not support the add or addAll operations. 它不支持add或addAll操作。

Specified by: 指定者:
values in interface Map 接口Map中的值

Returns: 返回:
a collection view of the values contained in this map 此地图中包含的值的集合视图

Since: 以来:
1.2 1.2

you can collect all the Values in a ArrayList Eg: 您可以在ArrayList中收集所有值,例如:

if you have like 如果你喜欢

   HashTable <Object,Type> hm;

then you can use 那么你可以使用

   ArrayList<Type> al= new ArrayList<Type>(hm.values());

all your values are now inside array list 您所有的值现在都在数组列表中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM