treeset java_Java TreeSet add()方法与示例

treeset java

TreeSet类的add()方法 (TreeSet Class add() method)

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

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

  • add() method is used to add the given object(ob) to this TreeSet when it does not already exist otherwise it ignores it.

    add()方法用于将给定对象(ob)添加到此TreeSet中,如果该对象尚不存在,否则它将忽略它。

  • add() 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.

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

  • add() method may throw an exception at the time of adding an object.

    add()方法在添加对象时可能会引发异常。

    ClassCastException: This exception may throw when the given parameter is incompatible.

    ClassCastException :如果给定参数不兼容,则可能引发此异常。

Syntax:

句法:

    public boolean add(Object ob);

Parameter(s):

参数:

  • Object ob – represents the object (ob) to be added in this TreeSet.

    对象ob –表示要在此TreeSet中添加的对象(ob)。

Return value:

返回值:

The return type of the method is boolean, it returns true when the given object (ob) is to be added successfully otherwise it returns false when the given object is already exists in this TreeSet.

该方法的返回类型为boolean ,当成功添加给定对象(ob)时,它返回true;否则,当此TreeSet中已经存在给定对象时,它返回false。

Example:

例:

// Java program to demonstrate the example 
// of boolean add(Object ob) method of TreeSet 
import java.util.*;
public class AddOfTreeSet {
public static void main(String[] args) {
// Instantiates a TreeSet object
TreeSet < String > tree_set = new TreeSet < String > ();
// By using add() method is to add
// the given object of this
// TreeSet if not exists
tree_set.add("C");
tree_set.add("C++");
tree_set.add("JAVA");
tree_set.add("PHP");
tree_set.add("SFDC");
// Display TreeMap 
System.out.println("TreeSet: " + tree_set);
}
}

Output

输出量

TreeSet: [C, C++, JAVA, PHP, SFDC]

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

treeset java

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

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

相关文章

php fpm www.conf,PHP7中php.ini、php-fpm和www.conf 配置

PHP7中php.ini、php-fpm和www.conf 配置php.ini是php运行核心配置文件,下面是一些常用配置extension_dir""● 设置PHP的扩展库路径expose_php Off● 避免PHP信息暴露在http头中display_errors Off● 避免暴露php调用mysql的错误信息log_errors On● 在关闭display…

服务器电流源泉ups电源的三大形式

还记得此前12306官网瘫痪&#xff0c;回家心切急于购票的我们只能感到无比心累。双十一前夕&#xff0c;守在购物车边准备疯狂购物的剁手党们&#xff0c;遇到一直呈现加载状态的页面&#xff0c;不得不感叹想要做马云背后的那个人也要大费周折。作为一个资深网民&#xff0c;不…

timer purge_Java Timer purge()方法与示例

timer purge计时器类purge()方法 (Timer Class purge() method) purge() method is available in java.util package. purge()方法在java.util包中可用。 purge() method is used to remove all canceled tasks from the task queue of this Timer. purge()方法用于从此Timer的…

大话Linux内核中锁机制之原子操作、自旋锁【转】

转自&#xff1a;http://blog.sina.com.cn/s/blog_6d7fa49b01014q7p.html 多人会问这样的问题&#xff0c;Linux内核中提供了各式各样的同步锁机制到底有何作用&#xff1f;追根到底其实是由于操作系统中存在多进程对共享资源的并发访问&#xff0c;从而引起了进程间的竞态。这…

hashmap put方法_Java HashMap put()方法与示例

hashmap put方法HashMap类的put()方法 (HashMap Class put() method) put() method is available in java.util package. put()方法在java.util包中可用。 put() method is used to link the given value element with the given key element in this HashMap. put()方法用于在…

java中jdom,java – JDOM中的命名空间(默认)

我正在尝试使用最新的JDOM包生成XML文档.我遇到了根元素和命名空间的问题.我需要生成这个根元素&#xff1a;xmlns"http://www.energystar.gov/manageBldgs/req"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://www.…

java enummap_Java EnumMap get()方法与示例

java enummapEnumMap类的get()方法 (EnumMap Class get() method) get() method is available in java.util package. get()方法在java.util包中可用。 get() method is used to get the value mapped with the given key element (key_ele) otherwise it returns null when no…

java后台json传递,后台json传递

json除了可以用于前台传递&#xff0c;还可用于后台之间传递。它可以传递List,Map,Bean等类型的数据。例如&#xff1a;User u1new User();u1.setUsername("zy");u1.setPassword("123");User u2new User();u2.setUsername("msl");u2.setPassword…

专家呼吁建安全漏洞信息共享机制并强化管控

近日&#xff0c;由中国网络空间安全协会主办&#xff0c;中国网络空间安全协会网络空间安全法律与公共政策专业委员会、北京邮电大学互联网治理与法律研究中心、公安部第三研究所网络安全法律研究中心、西安交通大学信息安全法律研究中心承办的《网络安全法&#xff08;草案二…

java的equals方法_Java Date equals()方法与示例

java的equals方法日期类equals()方法 (Date Class equals() method) equals() method is available in java.util package. equals()方法在java.util包中可用。 equals() method is used to check whether this date and the given object (o) are equals or not. equals()方法…

lnmp解析php,LNMP之 php解析

[rootLNMP ~]# vim /usr/local/nginx/conf/nginx.conf打开以下PHP 相关项且更改 scripts$fastcgi_script_name;> /usrlocal/nginx/html$fastcgi_script_name;location ~ \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param…

spring历史背景

1.2004年spring出现第一版本spring frameworl1.0 2.写代码永远是最简单的&#xff0c;后续的运维工作才是让人感到无助的 3.spring boot在运维方面做了很多工作&#xff0c;部署&#xff0c;监控&#xff0c;度量。结合spring cloud还可以实现服务发现&#xff0c;服务降级等功…

计算机网络中的传输协议是_计算机网络中的传输方式

计算机网络中的传输协议是传输方式 (Transmission Modes) The mechanism of transferring data or information between two linked devices connected over a network is referred to as Transmission Modes. 在通过网络连接的两个链接的设备之间传输数据或信息的机制称为传输…

https 密钥 php,https加密方式是什么

Https加密介绍Http直接通过明文在浏览器和服务器之间传递消息&#xff0c;容易被监听抓取到通信内容。Https采用对称加密和非对称加密结合的方式来进行通信。Https不是应用层的新协议&#xff0c;而是Http通信接口用SSL和TLS来加强加密和认证机制。加密方式对称加密&#xff1a…

一个前端框架应该有的一些公共函数

一、防止ie浏览器按backspace回退页面 //防止后退返回页面,如果非文本框、密码框、文本域控件&#xff0c;或控件非可用装填&#xff0c;则禁用后退按键 var uanavigator.userAgent.toLowerCase(); var isIEua.indexOf("msie")>-1; window.document.onkeydown fu…

Kruskal(P)和Prim(K)算法

最小生成树 (Minimum Spanning Tree) An MST is a subset of the edges of the connected, undirected graph that connect all the vertices together, in which there is no forming of a cycle and there should be minimum possible total edge weight. MST是已连接的无向图…

java get post 注解,GET/POST接收或发送数据的问题

在文章开始&#xff0c;先来回忆一下GET、POST这两种请求方式的区别。❈Http定义了与服务器交互的不同方法&#xff0c;最基本的方法有4种&#xff0c;分别是GET&#xff0c;POST&#xff0c;PUT&#xff0c;DELETE。URL全称是资源描述符&#xff0c;我们可以这样认为&#xff…

mybatis中sql语句传入多个参数方法

1 使用map <select id"selectRole" parameterType"map" resultType"RoleMap">SELECT id, roleName, noteFROM roleWHERE roleName LIKE Concat(%,#{roleName},%)and note like Concat(%,#{note},%)</select> 在接口中如下定义 List&…

kotlin半生对象_Kotlin程序| 随播对象特征

kotlin半生对象伴侣对象 (Companion object) If you need a function or a property to be tied to a class rather than to instances of it (similar to static in java), you can declare it inside a companion object: 如果需要将函数或属性绑定到类而不是实例(类似于java…

mysql安装注意步骤,mysql安装步骤

mysql安装步骤1、在官网下载对应的压缩文件&#xff0c;放到本地文件夹下&#xff0c;解压缩。2、配置Path环境变量&#xff1a;新增mysql的bin文件夹路径&#xff0c;C:\software\mysql-8.0.23-winx64\bin。3、在mysql根目录下新增my.ini配置文件。内容如下&#xff0c;basedi…