Home » Java programming language

Java Dictionary remove() Method with Example

Dictionary Class remove() method: Here, we are going to learn about the remove() method of Dictionary Class with its syntax and example.
Submitted by Preeti Jain, on February 13, 2020

Dictionary Class remove() method

  • remove() method is available in java.util package.
  • remove() method is used to remove the key-value pairs from this dictionary.
  • remove() method is a non-static method, so it is accessible with the class object and if we try to access the method with the class name then we will get an error.
  • remove() method may throw an exception at the time of removing key_value pairs.
    NullPointerException: This exception may throw when the given parameter is null exists.


    public abstract Value remove(Object key_ele);


  • Object key_ele – represents the key element to be removed from this dictionary.

Return value:

The return type of this method is Value, it returns value associated with the given key in this dictionary.


// Java program is to demonstrate the example of
// remove() method of Dictionary

import java.util.*;

public class RemoveOfDictionary {
    public static void main(String[] args) {
        // Instantiate a Hashtable object
        Dictionary dictionary = new Hashtable();

        // By using put() method is to
        // add an elements in Hashtable 
        dictionary.put(1, "C");
        dictionary.put(2, "C++");
        dictionary.put(3, "JAVA");
        dictionary.put(4, "PHP");
        dictionary.put(5, "SFDC");

        // Display dictionary
        System.out.println("dictionary: " + dictionary);

        // Here we are removing the key-value pairs 
        // exists on the given key element 4 in this
        // dictionary by using remove() method

        // Display Modified Dictionary
        System.out.println("dictionary: " + dictionary);


dictionary: {5=SFDC, 4=PHP, 3=JAVA, 2=C++, 1=C}
dictionary: {5=SFDC, 3=JAVA, 2=C++, 1=C}


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.