Java ConcurrentHashMap - clear()
clear 函数用于清理键值对之间的映射。通过这种方式,将清理 ConcurrentHashMap 映射。
语法
public void clear()
让我们看一个示例 −
示例
import java.util.concurrent.ConcurrentHashMap;
import java.util.*;
public class Demo{
public static void main(String[] args){
Map<String, String> my_map = new ConcurrentHashMap<String, String>();
my_map.put("This", "35");
my_map.put("is", "78");
my_map.put("sample", "99");
System.out.println("The map contains the below elements " + my_map);
my_map.clear();
System.out.println("The elements after the clear function is called on it " + my_map);
}
}输出
The map contains the below elements {This=35, is=78, sample=99}
The elements after the clear function is called on it {}一个名为 Demo 的类包含主函数。此处,创建一个映射的新实例,并使用“put”函数向其添加元素。显示元素,然后清除映射。现在,映射将不包含任何内容,当再次显示映射时可以看到这一点。
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程语言
C++
C#
MongoDB
MySQL
JavaScript
PHP