当前位置:网站首页>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 .
边栏推荐
- Pan Yueming helps Germany's Rochester Zodiac custom wristwatch
- Druids connect to mysql8.0.11
- [dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)
- WiFi 2.4g/5g/6g channel distribution
- LeetCode 1647. Minimum deletion times of unique character frequency
- How to solve the problem of requiring a password when accessing your network neighborhood on your computer
- China's coal industry investment strategic planning future production and marketing demand forecast report Ⓘ 2022 ~ 2028
- 3 environment construction -standalone
- Pooling idea: string constant pool, thread pool, database connection pool
- Codeforces Round #768 (Div. 1)(A-C)
猜你喜欢

How to switch between dual graphics cards of notebook computer

To rotate 90 degrees clockwise and modify the video format

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

Team collaborative combat penetration tool CS artifact cobalt strike
![[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)

Bluebridge cup Guoxin Changtian single chip microcomputer -- detailed explanation of schematic diagram (IV)

Morning flowers and evening flowers

Pooling idea: string constant pool, thread pool, database connection pool

webAssembly

The difference between SRAM and DRAM
随机推荐
Pooling idea: string constant pool, thread pool, database connection pool
Redis single thread and multi thread
DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power
WiFi 2.4g/5g/6g channel distribution
2022 safety officer-a certificate registration examination and summary of safety officer-a certificate examination
Yyds dry goods inventory Prometheus alarm Art
Rest参考
The 14th five year plan for the construction of Chinese Enterprise Universities and the feasibility study report on investment Ⓓ 2022 ~ 2028
pycuda._ driver. LogicError: explicit_ context_ dependent failed: invalid device context - no currently
[SRS] build a specified version of SRS
Programming language (1)
[sg function] lightoj Partitioning Game
Yyds dry goods inventory Spring Festival "make" your own fireworks
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
Morning flowers and evening flowers
STM32 multi serial port implementation of printf -- Based on cubemx
Common problems in multi-threaded learning (I) ArrayList under high concurrency and weird hasmap under concurrency
The 2022 global software R & D technology conference was released, and world-class masters such as Turing prize winners attended
Ten minutes will take you in-depth understanding of multithreading. Multithreading on lock optimization (I)
Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet