java-bubble sort (using comparator)

1. Create an ordinary Java Project, as shown below:
        
2. Sorter is an interface that defines two methods, as shown below:
    
3. MySorter is the implementation class of the interface Sorter, which rewrites the methods in the Sorter interface to sort and compare the arrays, as shown in the following figure:
       
4. MyTest is the main calling Java class, through the call interface, to sort the order and reverse order, as shown below:
            
5. The result is shown in the figure below, you can clearly see the effect of sorting:
        


Intelligent Recommendation

Java custom sort Comparator

Comparator Comparator is a comparator interface. o1 indicates that the preceding character, o2 indicates that the following characters, Java default ascending order. Return Value The return value is g...

Comparator custom sort in java

Comparator custom sorting in java: The Comparator interface can implement custom sorting. When implementing the Comparator interface, the compare method should be rewritten: int compare(Object o1, Obj...

COMPARATOR Custom Sort by Java

Java Compare Custom Sort: Comparator interface You can rewrite the COMPARE method when you implement a COMPARATOR interface: int COMPARE (Object O1, Object O2) Returns a basic type of integer If you a...

Comparator: Java custom sort

The following is a personal learning experience: The problem is how to write is desperation when implementing CompartAOR, how is it writing? First, you need to know two knowledge points: (1) .sort () ...

More Recommendation

Sort in Java Comparable and Comparator

Description: Objects in Java, under normal circumstances, only == and! =. Can't use> or <. However, development needs need to be used, such as sorting. How do you achieve it? Implement a Compara...

Java implementation comparator sort

Cattle ceremony Written it in accordance with the master's answer, but running always communication, does not know the reason, this time the number of test examples is very large, the data arrived by ...

Java Sort, Comparator, Comparable

Comparator interface Comparator is a comparator interface. If we need to control a certain order, the class itself does not support sorting (ie, there is no Comparable interface); then we can create a...

Sort by the COMPARATOR in Java -------

First, functional interface The interface only contains an abstract method, which can be simplified with anonymous objects and lambda expressions, such as interfaces. Second, CAMPARATOR comparator 3.C...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top