gpt4 book ai didi

Java 6 相当于 Integer.compare

转载 作者:搜寻专家 更新时间:2023-10-30 21:15:46 25 4
gpt4 key购买 nike

在 Java 7 中我可以使用 Integer.compare ,但是当我尝试在 Java 6 中使用它时,出现错误:

cannot find symbol
symbol : method compare(int,int)
location: class java.lang.Integer

如何在 Java 6 中创建类似的函数?

最佳答案

这在 doc 中指定:

Compares two int values numerically. The value returned is identical to what would be returned by: Integer.valueOf(x).compareTo(Integer.valueOf(y))

所以你可以使用:

Integer.valueOf(x).compareTo(Integer.valueOf(y))

How do create a similar function in Java 6?

源是开放的,你可以找到实现here .

public static int compare(int x, int y) {
return (x < y) ? -1 : ((x == y) ? 0 : 1);
}

关于Java 6 相当于 Integer.compare,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20035111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com