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

How to determine whether map is empty in java

王林
Release: 2020-06-30 12:00:15
Original
43186 people have browsed it

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());
    }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template