Home » Java programming language

Java Dictionary isEmpty() Method with Example

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

Dictionary Class isEmpty() method

  • isEmpty() method is available in java.util package.
  • isEmpty() method is used to check whether this dictionary has the key- pairs value or not.
  • isEmpty() method is a non-static method, 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.
  • isEmpty() method does not throw an exception at the time of checking the empty status of this dictionary.


    public abstract boolean isEmpty();


  • It does not accept any parameter.

Return value:

The return type of this method is boolean, it returns true when this Dictionary is empty otherwise it returns false.


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

import java.util.*;

public class IsEmptyOfDictionary {
    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 Hashtable elements
        System.out.println("dictionary: " + dictionary);

        // By using isEmpty() method is to check
        // whether this Dictionary is empty or not 
        boolean status = dictionary.isEmpty();

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


dictionary: {5=SFDC, 4=PHP, 3=JAVA, 2=C++, 1=C}
dictionary.isEmpty(): false


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.