当前位置:网站首页>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 .
边栏推荐
- LeetCode 540. A single element in an ordered array
- Harbor integrated LDAP authentication
- Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
- Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)
- Mindmanager2022 serial number key decompression installer tutorial
- SDMU OJ#P19. Stock trading
- The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation
- BUUCTF,Misc:LSB
- STM32 multi serial port implementation of printf -- Based on cubemx
- To rotate 90 degrees clockwise and modify the video format
猜你喜欢

QGIS grid processing DEM data reclassification
![Buuctf, web:[geek challenge 2019] buyflag](/img/02/d3add04f8145621bff35d46b82ba53.jpg)
Buuctf, web:[geek challenge 2019] buyflag
![[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

Mysql database - Advanced SQL statement (I)

How to solve the problem of requiring a password when accessing your network neighborhood on your computer

The reason why the computer runs slowly and how to solve it

Some 5000+ likes, the development notes of a director of cosmic factory, leaked

How to solve win10 black screen with only mouse arrow

How to solve the problem of computer networking but showing no Internet connection
![[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)](/img/6c/2d48d441fee1981a271319fd9f6c23.jpg)
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
随机推荐
(POJ - 2912) rochambau (weighted concurrent search + enumeration)
The overseas listing of Shangmei group received feedback, and brands such as Han Shu and Yiye have been notified for many times and received attention
C deep anatomy - the concept of keywords and variables # dry inventory #
Sed、Awk
6.2 normalization 6.2.5 third normal form (3NF)
Opengauss database log management guide
Covariance
The latest analysis of crane driver (limited to bridge crane) in 2022 and the test questions and analysis of crane driver (limited to bridge crane)
Buuctf, misc: sniffed traffic
Harbor integrated LDAP authentication
How to connect a laptop to a projector
How does sentinel, a traffic management artifact, make it easy for business parties to access?
How to store null value on the disk of yyds dry inventory?
Shell script three swordsman awk
Es6~es12 knowledge sorting and summary
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
STM32 multi serial port implementation of printf -- Based on cubemx
On my first day at work, this API timeout optimization put me down!
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)