hashset java_Java HashSet clear()方法与示例

hashset java

HashSet类的clear()方法 (HashSet Class clear() method)

  • clear() method is available in java.util package.

    clear()方法在java.util包中可用。

  • clear() method is used to clear all of the element exists from this HashSet.

    clear()方法用于清除此HashSet中存在的所有元素。

  • clear() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    clear()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • clear() method does not throw an exception at the time of clearing elements.

    clear()方法在清除元素时不会引发异常。

Syntax:

句法:

    public void clear();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is void, it returns nothing.

该方法的返回类型为void ,不返回任何内容。

Example:

例:

// Java program to demonstrate the example 
// of void clear() method of HashSet 
import java.util.*;
public class ClearOfHashSet {
public static void main(String[] args) {
// Instantiates a HashSet object
HashSet < String > hs = new HashSet < String > ();
// By using add() method is to add
// the given object of this HashSet 
hs.add("C");
hs.add("C++");
hs.add("JAVA");
hs.add("PHP");
hs.add("SFDC");
// Display HashSet
System.out.println("HashSet: " + hs);
// By using clear() method is to
// remove all of the elements exists
// in this HashSet
hs.clear();
//Display Modified HashSet
System.out.println("hs.clear(): " + hs);
}
}

Output

输出量

HashSet: [JAVA, C++, C, SFDC, PHP]
hs.clear(): []

翻译自: https://www.includehelp.com/java/hashset-clear-method-with-example.aspx

hashset java

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544151.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

推荐 17 个压箱底的常用类库

前言在java的庞大体系中&#xff0c;其实有很多不错的小工具&#xff0c;也就是我们平常说的&#xff1a;轮子。如果在我们的日常工作当中&#xff0c;能够将这些轮子用户&#xff0c;再配合一下idea的快捷键&#xff0c;可以极大得提升我们的开发效率。今天我决定把一些压箱底…

02、django中的上下文

2019独角兽企业重金招聘Python工程师标准>>> 1、譬如设置网站的名称,setting中设置变量&#xff1a; # setting.py SITE_NAME "我的小站"2、在view中写函数将该变量转换成字典,做返回值 from django.conf import settings def site_key(request):# 这里使…

enumset.allof_Java EnumSet allOf()方法与示例

enumset.allofEnumSet类的allOf()方法 (EnumSet Class allOf() method) allOf() method is available in java.util package. allOf()方法在java.util包中可用。 allOf() method is used to return Enumset that has all of the elements of the given element type (ele_ty). …

实战:10 种实现延迟任务的方法,附代码!

作者 | 磊哥来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;这篇文章的诞生要感谢一位读者&#xff0c;是他让这篇优秀的文章有了和大家见面的机会&#xff0c;重点是优秀文章&#xff…

netsh命令

C:\Windows\System32>netsh interface ipv6 show address levelverbose 地址 ::1 参数---------------------------------------------------------接口 Luid : Loopback Pseudo-Interface 1作用域 ID : 0.0有效生存时间 : infinite首选生存时间 : infiniteDAD 状态 : 首选项…

面渣逆袭:Redis连环五十二问!三万字+八十图详解!

基础1.说说什么是Redis?Redis图标Redis是一种基于键值对&#xff08;key-value&#xff09;的NoSQL数据库。比一般键值对数据库强大的地方&#xff0c;Redis中的value支持string&#xff08;字符串&#xff09;、hash&#xff08;哈希&#xff09;、 list&#xff08;列表&…

hdu 4864 Task(贪婪啊)

主题链接&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid4864 Task Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1346 Accepted Submission(s): 336Problem DescriptionToday the company has m ta…

svg学习网站

1、http://www.runoob.com/svg

EasyExcel太方便易用了,强烈推荐!

背景 系统中经常要导出大量的数据&#xff0c;格式基本上都是Excel&#xff0c;然而每次导表都是对系统内存的一次挑战。在Java领域&#xff0c;生成或解析Excel的框架比较有名的当属Apache的poi和jxl了。但使用它们&#xff0c;会面临着严重的内存损耗问题。如果系统的并发量还…

Java Date hashCode()方法与示例

日期类hashCode()方法 (Date Class hashCode() method) hashCode() method is available in java.util package. hashCode()方法在java.util包中可用。 hashCode() method is used to retrieve hash code of this Date object. hashCode()方法用于检索此Date对象的哈希码。 has…

eclispe快捷键

快捷键无效解决办法&#xff1a; 1、考虑是否被其他应用占用&#xff0c;如QQ&#xff0c;QQ音乐&#xff0c;千千动听等 2、在eclispe查看是否被修改&#xff1a;Window->Preferences->General->Keys 快捷键&#xff1a; 1、复制当前行到下一行&#xff1a;CtrlAlt↓…

【端午】送3本书!

白天在公司搬砖&#xff0c;晚上到家赶紧给小伙伴们安排一波福利&#xff0c;这次送的书是 H 大新出的《深入理解Java核心技术&#xff1a;写给Java工程师的干货笔记&#xff08;基础篇&#xff09;》。书中介绍了普通Java工程师必须要学习的相关知识点&#xff0c;包括面向对象…

java bitset_Java BitSet length()方法与示例

java bitsetBitSet类的length()方法 (BitSet Class length() method) length() method is available in java.util package. length()方法在java.util包中可用。 length() method is used to return the length of this BitSet otherwise it returns 0 when this BitSet is &qu…

SpriteBuilder物理对象的父子关系

注意:打开物理使能(Physics-enabled)的节点忽略他们的父节点关系. 这意味着,一个物理使能的子节点不会随着其父节点移动. 物理引擎对于节点父子关系这个概念毫不知情,因此单独的对待所有物理使能的节点,意味着这些节点与其他节点相互独立. 我强烈建议你在设计所有复杂物理对象的…

面试突击51:为什么单例一定要加 volatile?

.作者 | 磊哥来源 | Java面试真题解析&#xff08;ID&#xff1a;aimianshi666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;单例模式的实现方法有很多种&#xff0c;如饿汉模式、懒汉模式、静态内部类和枚举等&#xff0c;当面试官问到“为什…

kotlin 扩展类的功能_Kotlin程序| 扩展功能功能

kotlin 扩展类的功能扩展功能 (Extension function) Kotlin provides the ability to add more functionality to the existing class without inheriting them. Kotlin可以在不继承现有类的情况下为其添加更多功能。 This is done via a special declaration called "Ext…

聊聊保证线程安全的10个小技巧

前言对于从事后端开发的同学来说&#xff0c;线程安全问题是我们每天都需要考虑的问题。线程安全问题通俗的讲&#xff1a;主要是在多线程的环境下&#xff0c;不同线程同时读和写公共资源&#xff08;临界资源&#xff09;&#xff0c;导致的数据异常问题。比如&#xff1a;变…

Raid控制器

转载于:https://blog.51cto.com/xuepengdou/1699799

并行计算机架构_计算机科学组织| 并行处理

并行计算机架构并行处理 (Parallel Processing) Parallel processing is processing of the data concurrently. We process the data concurrently to fulfill the demands of the increasingly high performance so that to achieve better throughput instead of processing…

15个必知的Mysql索引失效场景,别再踩坑了!

背景 无论你是技术大佬&#xff0c;还是刚入行的小白&#xff0c;时不时都会踩到Mysql数据库不走索引的坑。常见的现象就是&#xff1a;明明在字段上添加了索引&#xff0c;但却并未生效。前些天就遇到一个稍微特殊的场景&#xff0c;同一条SQL语句&#xff0c;在某些参数下生效…