Hi all, I have:
Hashtable <String, Word> hw
How can I convert its values to:
ArrayList <Word> arr
thanks.
Hi all, I have:
Hashtable <String, Word> hw
How can I convert its values to:
ArrayList <Word> arr
thanks.
Use the ArrayList
constructor that takes a collection.
ArrayList<Word> arr = new ArrayList<Word>(hw.values());
Then every value that was in the HashTable
will be in the new ArrayList
.
You can find documentation about the constructor in the javadocs.
use
hw.values();
it will simply return the collection of Word
from javadocs
values
public Collection 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.