package com.hikeytech.d3.common.exception;
import java.util.Comparator;
public class Comparator_Integer {
public static void main(String[] args) {
System.out.println(naturalOrder.compare(new Integer(42), new Integer(42)));
}
static Comparator<Integer> naturalOrder = new Comparator<Integer>() {
public int compare(Integer a, Integer b) {
//必须先进行整数值转换,否则==比较时进行的是引用地址的比较
int i = a;
int j = b;
return i < j ? -1 : (i == j ? 0 : 1);
}
};
}
Comparator_Integer
最新推荐文章于 2023-09-23 08:00:00 发布