当前位置:网站首页>Differences between comparable and comparator
Differences between comparable and comparator
2022-06-30 02:57:00 【Ppdy bud】
List of articles
The same thing
Are used to compare objects
Difference
1、Comparable: stay java.lang It's a bag
Comparator: stay java.util It's a bag
2、Comparable: Need to rewrite compareTo(Object o) Method
Comparator: Need to rewrite compare(Object o1, Object o2) Method
3、comparable:① It's an internal comparator , Objects of this class can be directly compared with each other this.compareTo(this),② You can use it directly Collections.sort Methods the sorting
Comparator:① It's an external comparator , It didn't come true comparable You can also compare and sort compare(o1,o2)
4、omparator It is a typical strategy pattern
5、Comparable and Comparator There is ,Comparator High priority
6、Comparable: You need to modify the original entity class , It's a natural sort
Comparator: A comparator implemented without modifying the original class , Widely used in practice
边栏推荐
- Network neuroscience -- a review of network Neuroscience
- List of development tools
- Heavy attack -- ue5's open source digital twin solution
- Global and Chinese market for defense network security 2022-2028: Research Report on technology, participants, trends, market size and share
- Ffmpeg source code
- Visual HTA form designer htamaker interface introduction and usage, Download | HTA VBS visual script writing
- What are the three paradigms of database
- What is the concept of string in PHP
- How to use redis to realize the like function
- LeetCode 3. 无重复字符的最长子串
猜你喜欢

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

中断操作:AbortController学习笔记

Implementation of Sanzi chess with C language

Time complexity analysis

What is the concept of string in PHP

Some configuration details about servlet initial development

O & M (21) make winpe startup USB flash disk

Two methods of SSL certificate format conversion

Interrupt operation: abortcontroller learning notes
随机推荐
Two methods of SSL certificate format conversion
微信小程序页面跳转以及参数传递
002 color classification
mysqldump原理
Network neuroscience -- a review of network Neuroscience
Interrupt operation: abortcontroller learning notes
Série de tutoriels cmake - 02 - génération de binaires à l'aide du Code cmake
Raki's notes on reading paper: discontinuous named entity recognition as maximum clique discovery
Note the use of export/import and class inheritance in ES6
Jvxetable增加自定义按钮
原生JS怎么生成九宫格
HTA入门基础教程 | VBS脚本的GUI界面 HTA简明教程 ,附带完整历程及界面美化
Lua 基础知识
【直播笔记0629】 并发编程二:锁
Three solutions to forced hibernation of corporate computers
GTK interface programming (II): key components
Cmake tutorial series -05- options and variables
Which is a good foreign exchange trading platform? Is it safe to have regulated funds?
2022 new test questions for safety management personnel of metal and nonmetal mines (small open pit quarries) and certificate examination for safety management personnel of metal and nonmetal mines (s
备忘一下es6的export/import和类继承的用法