3:44 pm - Sunday June 25, 2017

Remove a value from HashMap by its key using remove(Object key )

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK  

                   This method is used to remove the mapping for the specified key and if the specified key is not available it returns null.

Example Program


import java.util.HashMap;

public class Hash2 {

	public static void main(String[] args)

	{

		HashMap<String, Integer> h1 = new HashMap<String, Integer>();

		System.out.println("collections");

		System.out.println("List");

		h1.put("Linked list", 0);

		h1.put("Array List", 1);

		h1.put("Vector", 2);

		h1.put("Stack", 3);

		System.out.println(h1);

		h1.remove("Stack");

		System.out.println("After removing hash key" + h1);

		System.out.println("the size of hash function is:\n" + h1.size());

	}

}

Output

   Collections

    List

    {Stack=3, Array List=1, Linked list=0, Vector=2}

     After removing hash key{Array List=1, Linked list=0, Vector=2}

      the size of hash function is: 3

BACK

Filed in: Java Examples

Comments are closed.