sortbypopulation.java

来自「用java写的字符串排序程序,可实现一个类的排序,实现了comparable接口」· Java 代码 · 共 29 行

JAVA
29
字号
package com.bemjh.sort;

import java.util.Comparator;

/**
 * Created by IntelliJ IDEA.
 * User: ma
 * Date: 2006-11-25
 * Time: 17:23:31
 * To change this template use File | Settings | File Templates.
 */
public class SortByPoPulation implements Comparator {
    private int direction;
    public SortByPoPulation(boolean ascending) {
        if(ascending){
            direction = 1;
        }
        else{
            direction = -1;
        }
    }

    public int compare(Object o1, Object o2) {
        Country country1 = (Country)o1;
        Country country2 = (Country)o2;
        return direction*country1.getPopulation().compareTo(country2.getPopulation());
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?