当前位置:网站首页>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 .
边栏推荐
- Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)
- Investment planning analysis and prospect prediction report of China's satellite application industry during the 14th five year plan Ⓑ 2022 ~ 2028
- The 14th five year plan and investment feasibility study report of China's industry university research cooperation Ⓧ 2022 ~ 2028
- On my first day at work, this API timeout optimization put me down!
- Mysql database - Advanced SQL statement (I)
- Code in keil5 -- use the code formatting tool astyle (plug-in)
- 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)
- Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet
- Conditional statements of shell programming
- The difference between SRAM and DRAM
猜你喜欢
Flutter internationalized Intl
2 spark environment setup local
Morning flowers and evening flowers
6.0 kernel driver character driver
The difference between SRAM and DRAM
The reason why the computer runs slowly and how to solve it
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
Quick one click batch adding video text watermark and modifying video size simple tutorial
How to solve the problem of requiring a password when accessing your network neighborhood on your computer
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
随机推荐
C3p0 connection MySQL 8.0.11 configuration problem
[dynamic planning] counting garlic customers: the log of garlic King (the longest increasing public subsequence)
STM32 multi serial port implementation of printf -- Based on cubemx
Blue Bridge Cup -- Mason prime
SDMU OJ#P19. Stock trading
Investment analysis and prospect trend prediction report of China's boron nitride industry Ⓨ 2022 ~ 2028
Report on the development strategy of China's engineering bidding agency and suggestions for the 14th five year plan Ⓙ 2022 ~ 2028
2 spark environment setup local
Development mode and Prospect of China's IT training industry strategic planning trend report Ⓣ 2022 ~ 2028
Oil monkey plug-in
1068. Consolidation of ring stones (ring, interval DP)
How to switch between dual graphics cards of notebook computer
Summary of fluent systemchrome
In 2022, 6G development has indeed warmed up
Report on the development status and investment planning trends of China's data center industry Ⓡ 2022 ~ 2028
Data consistency between redis and database
[Android reverse] use DB browser to view and modify SQLite database (download DB browser installation package | install DB browser tool)
Code in keil5 -- use the code formatting tool astyle (plug-in)
JS Demo calcule combien de jours il reste de l'année
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028