当前位置:网站首页>Comparable和Comparator的区别
Comparable和Comparator的区别
2022-06-30 02:52:00 【PPDY小芽】
相同点
都是用来对象之间的比较
不同点
1、Comparable:在java.lang包下
Comparator:在java.util包下
2、Comparable:需要重写compareTo(Object o)方法
Comparator:需要重写compare(Object o1, Object o2)方法
3、comparable:①是内在比较器,该类的对象可以直接相互比较this.compareTo(this),②可以直接使用Collections.sort方法排序
Comparator:①是外在比较器,没有实现comparable还想实现比较排序可以compare(o1,o2)
4、omparator 是典型的策略模式
5、Comparable和Comparator存在,Comparator优先级高
6、Comparable:需要修改原先的实体类,是一种自然的排序
Comparator:不用修改原先的类而实现的比较器,实际应用广
边栏推荐
- 学术汇报(academic presentation)/PPT应该怎么做?
- 怎样的外汇交易平台是有监管的,是安全的?
- 002 color classification
- NLP text summary: data set introduction and preprocessing [New York Times annotated corpus]
- 2. 成功解决 BUG:Exception when publishing, ...[Failed to connect and initialize SSH connection...
- Five cheapest wildcard SSL certificate brands
- Shenzhen CPDA Data Analyst Certification in July 2022
- threejs 镜子案例Reflector 创建镜子+房子搭建+小球移动
- 福利抽奖 | 开源企业级监控Zabbix6.0都有哪些亮点
- Software testing skills, JMeter stress testing tutorial, transaction controller of logic controller (25)
猜你喜欢

自定义JvxeTable的按钮及备注下$set的用法

Steam elements hidden in science and Technology Education

并发请求下如何防重复提交

LeetCode 3. 无重复字符的最长子串

How to prevent phishing emails? S/mime mail certificate

Série de tutoriels cmake - 02 - génération de binaires à l'aide du Code cmake

A quick look at the statistical data of 23 major cyber crimes from 2021 to 2022

CMake教程系列-02-使用cmake代码生成二进制

Two methods of SSL certificate format conversion

微信小程序页面跳转以及参数传递
随机推荐
NLP text summary: data set introduction and preprocessing [New York Times annotated corpus]
Pytoch learning (II)
Global and Chinese market of wind energy equipment logistics 2022-2028: Research Report on technology, participants, trends, market size and share
What about punctuation in the first column of unity text
What are the three paradigms of database
Unity TimeLine 数据绑定
Steam elements hidden in science and Technology Education
CMake教程系列-02-使用cmake代碼生成二進制
Cmake tutorial series-01-minimum configuration example
What is digicert smart seal?
中断操作:AbortController学习笔记
Network neuroscience——网络神经科学综述
C language pivot_ Invalid argument error resolution for root
Raki's notes on reading paper: discontinuous named entity recognition as maximum clique discovery
2.< tag-动态规划和0-1背包问题>lt.416. 分割等和子集 + lt.1049. 最后一块石头的重量 II
Five cheapest wildcard SSL certificate brands
[NPM] solve the problem of error reporting when installing typeorm with NPM
[on] [DSTG] dynamic spatiotemporalgraph revolutionary neural networks for traffic data impact
How do I enable assembly binding logging- How can I enable Assembly binding logging?
HTA introductory basic tutorial | GUI interface of vbs script HTA concise tutorial, with complete course and interface beautification