我是靠谱客的博主 执着帅哥,这篇文章主要介绍清除哈希表中的所有元素,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Remove all values from Java HashMap example This Java Example shows how to remove all values from HashMap object or empty HashMap or clear HashMap using clear method. */ import java.util.HashMap; public class EmptyHashMapExample { public static void main(String[] args) { // create HashMap object HashMap hMap = new HashMap(); // add key value pairs to HashMap hMap.put("1", "One"); hMap.put("2", "Two"); hMap.put("3", "Three"); /* * To remove all values or clear HashMap use void clear method() of * HashMap class. Clear method removes all key value pairs contained in * HashMap. */ hMap.clear(); System.out.println("Total key value pairs in HashMap are : " + hMap.size()); } } /* * Output would be Total key value pairs in HashMap are : 0 */

原文:http://www.java-examples.com/remove-all-values-java-hashmap-example


最后

以上就是执着帅哥最近收集整理的关于清除哈希表中的所有元素的全部内容,更多相关清除哈希表中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部