Properties void putAll(Map t) method Example Program


Copies all of the mappings from the specified map to this hashtable. These mappings will replace any mappings that this hashtable had for any of the keys currently in the specified map.

Program

package com.candidjava;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;

/* 
 * @author : Mohan 
 * @description : The putAll(Map<? extends K,? extends V> t) method is used to copy all of the mappings from the specified Map to this Hashtable.
 */
public class PropertiesPutAll {

	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);
		Map m=new HashMap();
		m.putAll(ht);
		System.out.println(m);

	}

}

Output

{5=karthick, 4=mohan, 3=vinoth, 2=anand, 1=hari}
{1=hari, 2=anand, 3=vinoth, 4=mohan, 5=karthick}

Explanation

public void putAll(Map<? extends K,? extends V> t)
Copies all of the mappings from the specified map to this hashtable. These mappings will replace any mappings that this hashtable had for any of the keys currently in the specified map.
Specified by:
putAll in interface Map<K,V>
Parameters:
t - mappings to be stored in this map
Throws:
NullPointerException - if the specified map is null
Since:
1.2


Related Post

Comments


©candidjava.com