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;
import java.util.Properties;
/*
* @author : Mohan
* @description : The values() method is used to get a Collection view of the values contained in this Hashtable.
*/
public class PropertiesValues {
public static void main(String[] args) {
Properties properties = new Properties();
Hashtable ht = new Hashtable(properties);
ht.put("1", "hari");
ht.put("2", "anand");
ht.put("3", "vinoth");
ht.put("4", "mohan");
ht.put("5", "karthick");
System.out.println(ht);
System.out.println(ht.values());
}
}
Output
{5=karthick, 4=mohan, 3=vinoth, 2=anand, 1=hari}
[karthick, mohan, vinoth, anand, hari]
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