Properties V remove(Object key) method Example Program


Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable.

Program

package com.candidjava;

import java.util.Hashtable;
import java.util.Properties;

/* 
 * @author : Mohan 
 * @description : The remove(Object key) method is used to remove the key (and its corresponding value) from this hashtable.
 */
public class ProperitiesRemove {

	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.remove("2"));
		System.out.println(ht);

	}

}

Output

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

Explanation

public V remove(Object key)
Removes the key (and its corresponding value) from this hashtable. This method does nothing if the key is not in the hashtable.
Specified by:
remove in interface Map<K,V>
Specified by:
remove in class Dictionary<K,V>
Parameters:
key - the key that needs to be removed
Returns:
the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping
Throws:
NullPointerException - if the key is null


Related Post

Comments


©candidjava.com