简体   繁体   中英

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?

Note:all the values are distinct 100% ,thats why i want to fetch blindly those data for further process

Take a look at Hashtable#values() :

public Collection<V> values()

Returns a Collection view of the values contained in this map. 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. The collection supports element removal, which removes the corresponding mapping from the map, via the Iterator.remove, Collection.remove, removeAll, retainAll and clear operations. It does not support the add or addAll operations.

Specified by:
values in interface Map

Returns:
a collection view of the values contained in this map

Since:
1.2

you can collect all the Values in a ArrayList Eg:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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