当前位置:网站首页>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 .
边栏推荐
- JS demo calculate how many days are left in this year
- How to store null value on the disk of yyds dry inventory?
- Opengauss database log management guide
- WFC900M-Network_ Card/Qualcomm-Atheros-AR9582-2T-2R-MIMO-802.11-N-900M-high-power-Mini-PCIe-Wi-Fi-Mod
- Leetcode: a single element in an ordered array
- Yyds dry goods inventory Prometheus alarm Art
- Pooling idea: string constant pool, thread pool, database connection pool
- Buuctf, web:[geek challenge 2019] buyflag
- Is the account opening of Guotai Junan Securities safe and reliable? How to open Guotai Junan Securities Account
- Mysql database - Advanced SQL statement (I)
猜你喜欢
540. Single element in ordered array
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)
[Android reverse] application data directory (files data directory | lib application built-in so dynamic library directory | databases SQLite3 database directory | cache directory)
BUUCTF,Misc:LSB
Blue Bridge Cup Guoxin Changtian MCU -- program download (III)
2022 safety officer-b certificate examination summary and safety officer-b certificate simulation test questions
[Android reverse] use DB browser to view and modify SQLite database (download DB browser installation package | install DB browser tool)
Quick one click batch adding video text watermark and modifying video size simple tutorial
Preliminary analysis of smart microwave radar module
Bluebridge cup Guoxin Changtian single chip microcomputer -- hardware environment (I)
随机推荐
[golang] leetcode intermediate - alphabetic combination of island number and phone number
C deep anatomy - the concept of keywords and variables # dry inventory #
1 Introduction to spark Foundation
Correlation
China HDI market production and marketing demand and investment forecast analysis report Ⓢ 2022 ~ 2028
Pat grade A - 1164 good in C (20 points)
Team collaborative combat penetration tool CS artifact cobalt strike
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
Tkinter Huarong Road 4x4 tutorial III
[dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)
Kali2021.4a build PWN environment
Go Technology Daily (2022-02-13) - Summary of experience in database storage selection
2022 G3 boiler water treatment registration examination and G3 boiler water treatment examination papers
Preliminary analysis of smart microwave radar module
Classification and extension of OC
The difference between SRAM and DRAM
Conditional statements of shell programming
Leetcode: a single element in an ordered array
Harbor integrated LDAP authentication
[automation operation and maintenance novice village] flask-2 certification