HashTable Collection values() Method Example Program


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.

Program

package com.candidjava;

import java.util.Hashtable;

/**
 * @author: Hari Haran
 * @discription: The values() method is used to get a Collection view of the
 *               values contained in this Hashtable.
 */

public class HashTableValues {
	public static void main(String args[]) {
		Hashtable<Integer, String> ht1 = new Hashtable<Integer, String>();

		ht1.put(1, "Anand");
		ht1.put(2, "Hari Haran");
		ht1.put(3, "Kamal");
		ht1.put(4, "Karthikeyan");
		ht1.put(5, "Mohan");
		ht1.put(6, "Vinoth");
		ht1.put(7, "Hari Haran");

		System.out.println("Collection view of hash table: " + ht1.values());
	}
}

Output

Collection view of hash table: [Hari Haran, Vinoth, Mohan, Karthikeyan, Kamal, Hari Haran, Anand]

Explanation

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<K,V>
Returns:
a collection view of the values contained in this map


Related Post

Comments


©candidjava.com