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

treeset java_Java TreeSet add()方法与示例相关推荐

  1. treeset java_Java TreeSet pollLast()方法与示例

    treeset java TreeSet类pollLast()方法 (TreeSet Class pollLast() method) pollLast() method is available i ...

  2. treeset java_Java TreeSet clear()方法与示例

    treeset java TreeSet类的clear()方法 (TreeSet Class clear() method) clear() method is available in java.u ...

  3. treeset java_Java TreeSet last()方法与示例

    treeset java TreeSet类的last()方法 (TreeSet Class last() method) last() method is available in java.util ...

  4. treeset java_Java TreeSet first()方法与示例

    treeset java TreeSet类的first()方法 (TreeSet Class first() method) first() method is available in java.u ...

  5. treeset java_Java TreeSet Higher()方法与示例

    treeset java TreeSet类Higher()方法 (TreeSet Class higher() method) higher() method is available in java ...

  6. treeset java_Java TreeSet iterator()方法与示例

    treeset java TreeSet类的iterator()方法 (TreeSet Class iterator() method) iterator() method is available ...

  7. treeset java_Java TreeSet ceiling()方法与示例

    treeset java TreeSet类ceiling()方法 (TreeSet Class ceiling() method) ceiling() method is available in j ...

  8. treeset比较器_Java TreeSet比较器()方法与示例

    treeset比较器 TreeSet类的compare()方法 (TreeSet Class comparator() method) comparator() method is available ...

  9. java calendar.add方法_Java Calendar add()方法与示例

    日历类add()方法add()方法在java.util包中可用. add()方法用于对指定的cal_fi(日历字段)执行相加或相减的时间量. add()方法是一个非静态方法,可通过类对象访问,如果尝试 ...

最新文章

  1. ubuntu mysql 驱动_怎么在Ubuntu下为MySQL添加ODBC驱动?
  2. c++ primer文本查询程序 自编加强版(c++primer5th 练习12.32-33)
  3. Spring集成文件轮询和测试
  4. 【.Net】C# 将Access中时间段条件查询的数据添加到ListView中
  5. 《南溪的目标检测学习笔记》——neck组件的设计笔记
  6. OBS推流工具使用说明
  7. 计算机联锁图册计算公式,计算机联锁图册认识文档
  8. C语言oj统计衣服尺寸,如何测量衣服尺寸?
  9. Android 自定义 View 实现转盘功能
  10. 大神f1 刷原生android,兼容多种ROM包 酷派大神F1堪称刷机神器
  11. nc65右键生成菜单_NC65管理员层级管控
  12. 华为平板可以安装python_平板电脑能否代替笔记本电脑?平板电脑购买指南
  13. 使用table标签制作常用的html表格
  14. Hdu 5804 Price List【水题】
  15. php脾组词,脾组词_脾字组词_脾的组词意思及拼音
  16. redis 健康检查
  17. WEB漏洞——SQL注入之简要SQL注入
  18. 在windows本地创建svn及遇到错误:svn create repository here 报错
  19. android开花动画,放下手机,听花开的声音 -- 花儿 の Time #Android #iPhone
  20. 最小二乘法:三种变形

热门文章

  1. java中并不是任意多个接口都可以实现多实现
  2. TVM:在树莓派上部署预训练的模型
  3. mysql 嵌入式 性能_database – 在mySQL中优化嵌入式SELECT查询
  4. java修改默认字符编码_设置默认的Java字符编码?
  5. c语言 函数指针开销,函数指针是否使程序变慢?
  6. 不越狱换壁纸_那些不舍得换的手机插画壁纸,你还差几张?
  7. 进程调度rr算法java实现_Java实现进程调度算法(二) RR(时间片轮转)
  8. ES备份工具elasticdump
  9. 安装python3.9
  10. Redis(零):背景