Comparison between Comparable and Comparator based on Java
Comparison between Comparable and Comparator in Java
Introduction to Comparable
Comparable is a sort interface.
If a class implements the Comparable interface, it means that "this class supports sorting". That is, classes that implement the Comparable interface support sorting. Assuming that there is a "List (or array) o ...
Posted by kevo1162 on Thu, 17 Feb 2022 05:25:03 +0100
Java -- Set 2-3 (Set)
Set
Set set overview and features
Set set features
A collection that does not contain duplicate elementsThere is no indexed method, so you can't use a normal for loop to traverse
Set set exercise
Store string and traverse
import java.util.HashSet;
import java.util.Set;
/*
Set Set characteristics
A collection that does not contain dupli ...
Posted by Ryanmcgrim on Fri, 31 Dec 2021 11:15:54 +0100
An article takes you to a deeper understanding of Comparable and Comparator
Whenever a sort sensitive class is implemented, it should implement the Comparable interface so that its instances can be easily classified, searched, and used in comparison based collections
Whenever you compare field values in the comparTo method, you should avoid using the < and > operators. Instead, you should use the static compare ...
Posted by jerry_louise on Fri, 29 Oct 2021 06:11:43 +0200