Home >Java >javaTutorial >How to determine whether map is empty in java

How to determine whether map is empty in java

王林
王林Original
2020-06-22 14:03:4643107browse

The way to determine whether a map is empty in Java is: you can use the isEmpty() function to determine. The isEmpty() function is a system library function in Java that is used to determine whether a certain container has elements. For example, it is used to determine whether ArrayList, HashSet, HashMap has elements, etc.

How to determine whether map is empty in java

The way to determine whether a map is empty in Java is to use the isEmpty() function to determine.

(Recommended learning: java introductory program)

Function introduction:

IsEmpty() is used in Java to determine a certain container Is there a system library function for elements. For example, it can be used to determine whether ArrayList, HashSet, HashMap has elements, etc.

In Java, you can use isEmpty(); to determine whether there are elements in a sequence container ArrayList. If there are elements, return a Boolean value false, otherwise return true.

Sample code:

public static void main(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
        System.out.println("map为空:" + map.isEmpty());
        //加入元素
        map.put("1", "1");
        System.out.println("map为空:" + map.isEmpty());
    }

Output result:

How to determine whether map is empty in java

(Video tutorial recommendation: java video tutorial)

The above is the detailed content of How to determine whether map is empty in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn