当前位置:网站首页>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:不用修改原先的类而实现的比较器,实际应用广
边栏推荐
- IBM WebSphere channel connectivity setup and testing
- Distributed file storage system fastdfs hands on how to do it
- GTK interface programming (I): Environment Construction
- 【postgres】postgres 数据库迁移
- Five cheapest wildcard SSL certificate brands
- High paid programmers & interview questions series 63: talk about the differences between sleep (), yield (), join (), and wait ()
- HTA introductory basic tutorial | GUI interface of vbs script HTA concise tutorial, with complete course and interface beautification
- 打造创客教育中精湛技艺
- 中断操作:AbortController学习笔记
- Global and Chinese market of subscription revenue management software 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

重磅来袭--UE5的开源数字孪生解决方案

2.8 【 weight of complete binary tree 】

Ffmpeg source code

Five cheapest wildcard SSL certificate brands

微信小程序页面跳转以及参数传递

论文回顾:Playful Palette: An Interactive Parametric Color Mixer for Artists

GTK interface programming (I): Environment Construction

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

Differences among digicert, SECTIONO and globalsign code signing certificates

oracle怎么设置密码复杂度及超时退出的功能
随机推荐
CMake教程系列-01-最小配置示例
Pytorch学习(二)
Cmake tutorial series -02- generating binaries using cmake code
Cmake tutorial series -04- compiling related functions
Redis+AOP怎么自定义注解实现限流
oracle怎么设置密码复杂度及超时退出的功能
Steam elements hidden in science and Technology Education
Distributed file system fastdfs
Differences among digicert, SECTIONO and globalsign code signing certificates
Detailed explanation of minimum stack
Pytoch learning (II)
How does native JS generate Jiugong lattice
How can redis+aop customize annotations to achieve flow restriction
Xunwei NXP itop-imx6 development platform
Two methods of SSL certificate format conversion
What files does a CA digital certificate contain? How to view SSL certificate information?
Study diary: February 15, 2022
Unity3D UGUI强制刷新Layout(布局)组件
Enlightenment from the revocation of Russian digital certificate by mainstream CA: upgrade the SSL certificate of state secret algorithm to help China's network security to be autonomous and controlla
Template parameter package and function parameter package