当前位置:网站首页>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 .
边栏推荐
- C3p0 connection MySQL 8.0.11 configuration problem
- Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
- Can you draw with turtle?
- Blue Bridge Cup -- guess age
- Harbor integrated LDAP authentication
- 540. Single element in ordered array
- Awk getting started to proficient series - awk quick start
- 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
- Sed、Awk
- Take you to master the formatter of visual studio code
猜你喜欢
![[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)](/img/29/543dce2f24130d22c1824385fbfa8f.jpg)
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)

webAssembly

string
![[automation operation and maintenance novice village] flask-2 certification](/img/9a/a9b45e1f41b9b75695dcb06c212a69.jpg)
[automation operation and maintenance novice village] flask-2 certification
![[actual combat record] record the whole process of the server being attacked (redis vulnerability)](/img/9c/34b916aca2f9270ec4cf4651f0de7e.jpg)
[actual combat record] record the whole process of the server being attacked (redis vulnerability)

2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions

Summary of basic knowledge of exception handling

1068. Consolidation of ring stones (ring, interval DP)

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

Blue Bridge Cup -- guess age
随机推荐
string
Pooling idea: string constant pool, thread pool, database connection pool
Yyds dry goods inventory hands-on teach you to create a jigsaw puzzle using the canvasapi
Take you to master the formatter of visual studio code
Market layout planning and latest dynamic analysis report of China's smart public security industry Ⓕ 2022 ~ 2028
2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
Awk getting started to proficient series - awk quick start
Buuctf, web:[geek challenge 2019] buyflag
[sg function] 2021 Niuke winter vacation training camp 6 h. winter messenger 2
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
Report on the development strategy of China's engineering bidding agency and suggestions for the 14th five year plan Ⓙ 2022 ~ 2028
Plug - in Oil Monkey
How can enterprises and developers take advantage of the explosion of cloud native landing?
STM32 multi serial port implementation of printf -- Based on cubemx
2022 free examination questions for safety management personnel of hazardous chemical business units and reexamination examination for safety management personnel of hazardous chemical business units
Shell script three swordsman awk
webAssembly
pivot ROP Emporium
Learning notes of raspberry pie 4B - IO communication (SPI)
[template summary] - binary search tree BST - Basics