Get the App
SLTechnology News&Howtos  ›  Development  › 

What does Comparators mean in java

Shulou Source: shulou.com Published: 2022-05-31 17:50:53 10月02日 Update

Most people do not understand the knowledge points of this article "what does Comparators in java refer to?", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what Comparators refers to in java" article.

Description

1. Comparator is a commonly used interface in old versions of Java, and Java8 adds many default methods to this interface.

2. Comparator is an interface in javase, which is located under the java.util package. This interface is very abstract and needs to know its usage.

In most cases, comparator is used for sorting, but sorting is one of the functions that comparator can achieve, and it is not limited to sorting.

Example

Comparator comparator = (p1, p2)-> p1.firstName.compareTo (p2.firstName); Person p1 = new Person ("John", "Doe"); Person p2 = new Person ("Alice", "Wonderland"); comparator.compare (p1, p2); / / > 0comparator.reversed (). Compare (p1, p2) / / more than 0 is the content of the article "what does Comparators in java refer to". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to learn more about the relevant knowledge, please follow the industry information channel.

Tags: Content ranking situation interface article interface knowledge article value function most examples that is commonly used methods more steps versions knowledge points industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB NVidia macOS Shulou Technology Microsoft