当前位置:网站首页>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:不用修改原先的类而实现的比较器,实际应用广
边栏推荐
- 自定义JvxeTable的按钮及备注下$set的用法
- How to modify and add fields when MySQL table data is large
- Idea remote debugging remote JVM debug
- 原生JS怎么生成九宫格
- Raki's notes on reading paper: Leveraging type descriptions for zero shot named entity recognition and classification
- Intel-Hex , Motorola S-Record 格式详细解析
- 2022 the action of protecting the net is imminent. Things about protecting the net
- Shenzhen CPDA Data Analyst Certification in July 2022
- How to switch ipykernel to a different CONDA virtual environment in jupyterlab?
- How to prevent phishing emails? S/mime mail certificate
猜你喜欢

Five cheapest wildcard SSL certificate brands

HTA入门基础教程 | VBS脚本的GUI界面 HTA简明教程 ,附带完整历程及界面美化

学术汇报(academic presentation)/PPT应该怎么做?

Unity3d ugui force refresh of layout components

FDA mail security solution

uniapp 地址转换经纬度

Créer des compétences exquises dans l'éducation des créateurs

Three solutions to forced hibernation of corporate computers

Playful palette: an interactive parametric color mixer for artists

Linear algebra Chapter 4 Summary of knowledge points of linear equations (Jeff's self perception)
随机推荐
Raii memory management
CMake教程系列-02-使用cmake代碼生成二進制
LeetCode 3. Longest substring without duplicate characters
How does native JS generate Jiugong lattice
How to prevent duplicate submission under concurrent requests
Idea remote debugging remote JVM debug
[on] [DSTG] dynamic spatiotemporalgraph revolutionary neural networks for traffic data impact
Global and Chinese markets for wireless security in LTE networks 2022-2028: Research Report on technology, participants, trends, market size and share
2.< tag-动态规划和0-1背包问题>lt.416. 分割等和子集 + lt.1049. 最后一块石头的重量 II
Threejs mirror case reflector create mirror + house construction + small ball movement
oracle怎么设置密码复杂度及超时退出的功能
Distributed file storage system fastdfs hands on how to do it
What are the requirements for NPDP product manager international certification examination?
在php中字符串的概念是什么
2. < tag dynamic programming and 0-1 knapsack problem > lt.416 Split equal sum subset + lt.1049 Weight of the last stone II
Global and Chinese market of mobile commerce solutions 2022-2028: Research Report on technology, participants, trends, market size and share
微信小程序页面跳转以及参数传递
Heavy attack -- ue5's open source digital twin solution
Série de tutoriels cmake - 02 - génération de binaires à l'aide du Code cmake
CMake教程系列-02-使用cmake代码生成二进制