当前位置:网站首页>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 .
边栏推荐
- Development trend and market demand analysis report of China's energy storage battery industry Ⓩ 2022 ~ 2028
- [automation operation and maintenance novice village] flask-2 certification
- Some 5000+ likes, the development notes of a director of cosmic factory, leaked
- Es6~es12 knowledge sorting and summary
- China's Call Center Industry 14th five year plan direction and operation analysis report Ⓔ 2022 ~ 2028
- Is it safe and reliable to open an account and register for stock speculation? Is there any risk?
- [dynamic programming] Jisuan Ke: Jumping stake (variant of the longest increasing subsequence)
- Pointer concept & character pointer & pointer array yyds dry inventory
- SDNU_ ACM_ ICPC_ 2022_ Winter_ Practice_ 4th [individual]
- Summary of basic knowledge of exception handling
猜你喜欢

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)

C deep anatomy - the concept of keywords and variables # dry inventory #
![Buuctf, web:[geek challenge 2019] buyflag](/img/02/d3add04f8145621bff35d46b82ba53.jpg)
Buuctf, web:[geek challenge 2019] buyflag

Niuke winter vacation training camp 4 g (enumeration optimization, Euler power reduction)

How can enterprises and developers take advantage of the explosion of cloud native landing?

What are the common computer problems and solutions

In 2022, 6G development has indeed warmed up

This time, thoroughly understand bidirectional data binding 01

IDENTITY

Cesium terrain clipping draw polygon clipping
随机推荐
Take you to master the formatter of visual studio code
Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)
How to obtain opensea data through opensea JS
[flax high frequency question] leetcode 426 Convert binary search tree to sorted double linked list
Leetcode: a single element in an ordered array
How to switch between dual graphics cards of notebook computer
Blue Bridge Cup Guoxin Changtian single chip microcomputer -- software environment (II)
股票炒股开户注册安全靠谱吗?有没有风险的?
The difference between SRAM and DRAM
Tkinter Huarong Road 4x4 tutorial III
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant
Harbor integrated LDAP authentication
[dynamic programming] Ji Suan Ke: Suan tou Jun breaks through the barrier (variant of the longest increasing subsequence)
Summary of fluent systemchrome
Data consistency between redis and database
Morning flowers and evening flowers
The latest analysis of R1 quick opening pressure vessel operation in 2022 and the examination question bank of R1 quick opening pressure vessel operation
油猴插件
6.2 normalization 6.2.5 third normal form (3NF)
Buuctf, misc: n solutions