| |

VerySource

 Forgot password?
 Register
Search
Author: blackedge

java sort method?

[Copy link]

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-4-12 11:45:01
| Show all posts
Comparator uses the above code

If o1 <o2 then return less than 0
If o1 == o2 then return 0
If o1> o2 then return greater than 0


As for how to determine the size of o1 and o2, compared with your code, above I compared o1.score and o2.score


If it is in descending order, change return p2.getScore ()-p1.getScore ();
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Invalid IP Address

Post time: 2020-4-14 09:00:01
| Show all posts
//: c11: DirList.java
// Displays directory listing.
// From 'Thinking in Java, 3rd ed.' (C) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
package org.luyang.collections;

import java.util.Arrays;
import java.util.Comparator;

public class Sort {
    public static String sort1 = "BIG_TO_SMALL";

    public static String sort2 = "SMALL_TO_BIG";

    public static void main (String [] args) {

        String [] list = new String [] {"C1", "A2", "B1", "E1", "D1", "F1"};

        Arrays.sort (list, new AlphabeticComparator1 (sort2));
        for (int i = 0; i <list.length; i ++)
            System.out.println (list [i]);
    }
}

class AlphabeticComparator1 implements Comparator {
    String sort = null;

    public AlphabeticComparator1 (String sort) {
        this.sort = sort;
    }

    public int compare (Object o1, Object o2) {
        String s1 = (String) o1;
        String s2 = (String) o2;
        if ("SMALL_TO_BIG" .equalsIgnoreCase (sort)) {
            return s1.toLowerCase (). compareTo (s2.toLowerCase ());
        } else {
            return s1.toLowerCase (). compareTo (s2.toLowerCase ()) * -1;
        }
    }
} // /: ~
Reply

Use magic Report

1

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-6-19 16:45:02
| Show all posts
Since the score and the person's ID are good, I want to use treemap to put the data. Is it okay to arrange it according to the score?
Reply

Use magic Report

1

Threads

6

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

 Author| Post time: 2020-6-20 13:45:01
| Show all posts
Does this affect the speed every time I open the page? I am considering whether to put the data in the table, and then query from the table, one month is a cycle, that is, the data of this time is displayed within one month, and rescanned in the next cycle. I think it can be put?
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-16 17:45:01
| Show all posts
This requirement, can't you add orderby when the database is checking data?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list