当前位置:网站首页>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 .
边栏推荐
- Codeforces Round #768 (Div. 1)(A-C)
- Common problems in multi-threaded learning (I) ArrayList under high concurrency and weird hasmap under concurrency
- Redis single thread and multi thread
- DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
- [Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)
- Harbor integrated LDAP authentication
- pycuda._ driver. LogicError: explicit_ context_ dependent failed: invalid device context - no currently
- Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)
- Classification and extension of OC
- IPhone development swift foundation 09 assets
猜你喜欢

Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?

User login function: simple but difficult

Data consistency between redis and database

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

Blue Bridge Cup -- Mason prime

What indicators should be paid attention to in current limit monitoring?

Flutter internationalized Intl
![[Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)](/img/b8/e2a59772d009b6ee262fb4807f2cd2.jpg)
[Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)

The difference between SRAM and DRAM
![[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
随机推荐
Electronic tube: Literature Research on basic characteristics of 6j1
Pooling idea: string constant pool, thread pool, database connection pool
Blue Bridge Cup -- Mason prime
[actual combat record] record the whole process of the server being attacked (redis vulnerability)
[Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)
Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?
Codeforces Round #768 (Div. 1)(A-C)
Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
LeetCode 1647. Minimum deletion times of unique character frequency
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- led lamp module (V)
[template summary] - binary search tree BST - Basics
LeetCode 540. A single element in an ordered array
LeetCode 1646. Get the maximum value in the generated array
China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
C deep anatomy - the concept of keywords and variables # dry inventory #
How to switch between dual graphics cards of notebook computer
Mysql database - Advanced SQL statement (I)
[sg function] lightoj Partitioning Game
Firefox set up proxy server
Report on the development strategy of China's engineering bidding agency and suggestions for the 14th five year plan Ⓙ 2022 ~ 2028