当前位置:网站首页>Comparable interface and comparator interface
Comparable interface and comparator interface
2022-07-03 22:30:00 【Crazy DIU DIU DIU】
comparable Interface and comparator The difference and usage of interface implementation comparison
1. Definition
Comparable Interface :
Use Array or Collection The sorting method of , Custom classes need to implement Java Provide Comparable Interface compareTo(TOBJ) Method , It is used by the sorting method , This method should be rewritten , If “this” Object is smaller than the object parameters passed 、 Equal or greater , It returns a negative integer 、0 Or a positive integer
Comparator Interface :
You can compare the specific fields of two objects ( such as , Compare the age of the employee ), Of this interface compare(Objecto1, Object o2) The implementation of the method needs to pass two object parameters , If the first parameter is less than 、 be equal to 、 Greater than second parameter , Returns a negative integer 、0、 Positive integer
comparable Interface and comparator Interface difference
- Comparable and Comparator Interfaces are used to sort collections or arrays of objects
- Comparable Interfaces are used to provide natural ordering of objects , It can be used to provide sorting based on a single logic
- Comparator Interfaces are used to provide different sort algorithms , You can select the required Comparator To sort the specified set of objects .
边栏推荐
- Es6~es12 knowledge sorting and summary
- Data consistency between redis and database
- To rotate 90 degrees clockwise and modify the video format
- Summary of fluent systemchrome
- Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
- On my first day at work, this API timeout optimization put me down!
- Market layout planning and latest dynamic analysis report of China's smart public security industry Ⓕ 2022 ~ 2028
- Sow of PMP
- [sg function] lightoj Partitioning Game
- Pat grade A - 1164 good in C (20 points)
猜你喜欢

Programming language (1)
![[golang] leetcode intermediate - alphabetic combination of island number and phone number](/img/40/a664ea866ce355c1f5e9305fe91780.jpg)
[golang] leetcode intermediate - alphabetic combination of island number and phone number

Data consistency between redis and database

Pooling idea: string constant pool, thread pool, database connection pool

Pan Yueming helps Germany's Rochester Zodiac custom wristwatch

Mysql database - Advanced SQL statement (I)

3 environment construction -standalone

Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)

On my first day at work, this API timeout optimization put me down!

QGIS grid processing DEM data reclassification
随机推荐
4 environment construction -standalone ha
Exclusive interview with the person in charge of openkruise: to what extent has cloud native application automation developed now?
Buuctf, misc: sniffed traffic
Dynamic research and future planning analysis report of China's urban water supply industry Ⓝ 2022 ~ 2028
Shell script three swordsman awk
Teach you how to run two or more MySQL databases at the same time in one system
Data consistency between redis and database
Buuctf, misc: n solutions
[Android reverse] use DB browser to view and modify SQLite database (download DB browser installation package | install DB browser tool)
Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)
[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
Label coco format data and format data in the upper left corner and lower right corner are mutually converted
On my first day at work, this API timeout optimization put me down!
Cesium terrain clipping draw polygon clipping
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
How to solve the problem of requiring a password when accessing your network neighborhood on your computer
Report on the current situation and development trend of ethoxylated sodium alkyl sulfate industry in the world and China Ⓞ 2022 ~ 2027
QGIS grid processing DEM data reclassification
[Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)