treeset java_Java TreeSet first()方法与示例

treeset java

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

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

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

  • first() method is used to retrieve the first lowest element in this TreeSet.

    first()方法用于检索此TreeSet中的第一个最低元素。

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

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

  • first() method may throw an exception at the time of returning the first least object in this TreeSet.

    返回此TreeSet中的第一个最小对象时, first()方法可能会引发异常。

    NoSuchElementException – This exception may throw when this TreeSet is “blank”.

    NoSuchElementException-如果此TreeSet为“空白”,则可能引发此异常。

Syntax:

句法:

    public Element first();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is Element, it gets the first least element exists in this TreeSet.

方法的返回类型为Element ,它获取此TreeSet中存在的第一个最小元素。

Example:

例:

// Java program to demonstrate the example 
// of Element first() method of TreeSet 
import java.util.*;
public class FirstOfTreeSet {
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 
tree_set.add("C");
tree_set.add("C++");
tree_set.add("JAVA");
tree_set.add("PHP");
tree_set.add("SFDC");
// Display TreeSet
System.out.println("TreeSet: " + tree_set);
// By using first() method is to return
// the first least element exists in this TreeSet
Object first_least = tree_set.first();
// Display first_least
System.out.println("tree_set.first(): " + first_least);
}
}

Output

输出量

TreeSet: [C, C++, JAVA, PHP, SFDC]
tree_set.first(): C

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

treeset java

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

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

相关文章

Java常用类:7000字一次性帮你总结好啦!

来源&#xff1a;cnblogs.com/lwtyyds/p/15678152.html常用类概述内部类内部类的分类&#xff1a;1.成员内部类&#xff08;非静态内部类&#xff09;2.局部内部类4.匿名内部类Object类Object类常用方法&#xff1a;1.equals方法2.hashCode方法3.toString方法4.finzlize方法包装…

CentOS6.4系统启动失败故障排查

转&#xff1a;http://www.centoscn.com/CentosBug/osbug/2014/1028/4011.html 操作系统启动失败如下图报错&#xff1a; 故障现象&#xff1a; 从图中可以看到&#xff0c;操作系统启动的过程中&#xff0c;fsck在执行文件系统检测时出现了错误&#xff0c;并且是在检查/dev/m…

hashmap clone_Java HashMap clone()方法与示例

hashmap cloneHashMap类clone()方法 (HashMap Class clone() method) clone() method is available in java.util package. clone()方法在java.util包中可用。 clone() method is used to get a cloned copy of this HashMap instance or in other words, we can say it return…

Linux内存管理--物理内存分配【转】

转自&#xff1a;http://blog.csdn.net/myarrow/article/details/8682819 1. First Fit分配器 First Fit分配器是最基本的内存分配器&#xff0c;它使用bitmap而不是空闲块列表来表示内存。在bitmap中&#xff0c;如果page对应位为1&#xff0c;则表示此page已经被分配&#xf…

JDK的一个Bug,监听文件变更要小心了

背景 在某些业务场景下&#xff0c;我们需要自己实现文件内容变更监听的功能&#xff0c;比如&#xff1a;监听某个文件是否发生变更&#xff0c;当变更时重新加载文件的内容。看似比较简单的一个功能&#xff0c;但如果在某些JDK版本下&#xff0c;可能会出现意想不到的Bug。本…

hashset java_Java HashSet clear()方法与示例

hashset javaHashSet类的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中…

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