Java Map. Clear() method: removes all mapping relationships from the map collection
•
Java
clear()
Example
public static void main(String[] args){
Map map = new HashMap(); //定义Map集合
map.put("昨天","定制目录"); //向集合中添加元素
map.put("今天","开始写作");
map.put("明天","当然继续写作");
System.out.println("map大小为:"+map.size()); //输出集合大小
map.clear(); //清除Map集合的所有内容
System.out.println("清除内容后的map大小是:"+map.size());
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
