当前位置:网站首页>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 .
边栏推荐
- Learning notes of raspberry pie 4B - IO communication (SPI)
- Pat grade A - 1164 good in C (20 points)
- IDENTITY
- JS closure knowledge points essence
- string
- Buuctf, web:[geek challenge 2019] buyflag
- Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
- On my first day at work, this API timeout optimization put me down!
- IPhone development swift foundation 09 assets
- [dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)
猜你喜欢

Covariance

Flutter internationalized Intl

Unique in China! Alibaba cloud container service enters the Forrester leader quadrant

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

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

Electronic tube: Literature Research on basic characteristics of 6j1

Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)

Mysql database - Advanced SQL statement (I)

540. Single element in ordered array

Some 5000+ likes, the development notes of a director of cosmic factory, leaked
随机推荐
[automation operation and maintenance novice village] flask-2 certification
Buuctf, misc: n solutions
Correlation
2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers
Buuctf, web:[geek challenge 2019] buyflag
[SRS] build a specified version of SRS
Pan Yueming helps Germany's Rochester Zodiac custom wristwatch
2 spark environment setup local
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
[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
JS demo calculate how many days are left in this year
540. Single element in ordered array
How to store null value on the disk of yyds dry inventory?
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
SDMU OJ#P19. Stock trading
On my first day at work, this API timeout optimization put me down!
How to obtain opensea data through opensea JS
Market layout planning and latest dynamic analysis report of China's smart public security industry Ⓕ 2022 ~ 2028
1 Introduction to spark Foundation