Discover java compareto implementation, include the articles, news, trends, analysis and practical advice about java compareto implementation on alibabacloud.com
In Java we often use the comparable interface to implement sorting, where CompareTo is implementing the interface method. We know that CompareTo returns 0 means that two objects are equal, a positive number represents greater than, and a negative
For the comparator interface and comparable interface, and their respective methods, compare (), compareTo (), and compareto
Two of the LeetCode questions today show the use of interfaces to sort objects. Links to the two questions are as follows:
1.
1. compareto is used for treeset, while treeset personally thinks it is best to read the DB result set. In the future, subset can be obtained based on compareto sorting results. When writing a database, you can use hashset instead of treeset,
In today's leetcode, there are two of them. The use of interfaces to implement the ordering of objects. RELATED links to the two questions:1. Sorting objects using the comparable interface2. Using comparator interface to achieve sortingBecause the
CompareAs can be seen from here, compare is a class in the comparator interface, and then look at the explanation in the source code
Compares its-arguments for order. Returns a negative integer,Zero, or a positive integer as the first
Java Collections OverviewOn the one hand, object-oriented language is the embodiment of things in the form of objects, in order to facilitate the operation of multiple objects, it is necessary to store objects. On the other hand, there are drawbacks
The details and differences of Java comparable and Comparator
Java provides us with two comparison mechanisms: comparable and Comparator, what is the difference between them? Come to understand today.
Comparable natural sort
Comparable under the
If there is reprint, please indicate the source: http://blog.csdn.net/yihui823/article/details/6866801
It is not a literal translation. It adds your own understanding. If you have any questions, please let us know.
Based on version: findbugs version
Tag: null override cannot serial failed RBO entity i++ dataAfter reading this article you will learn:
Comparable natural sort
Comparator Custom Sorting
Summarize
There are two comparison mechanisms
In Java container Study Notes (1), I have outlined the basic concepts and interface implementation of collection, and summarized the implementation and usage of an important subinterface list and its sub-classes.
This article mainly summarizes the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.