compareTo with primitives -> Integer / int
2022-08-31 14:04:46
写得更好吗
int primitive1 = 3, primitive2 = 4;
Integer a = new Integer(primitive1);
Integer b = new Integer(primitive2);
int compare = a.compareTo(b);
或
int primitive1 = 3, primitive2 = 4;
int compare = (primitive1 > primitive2) ? 1 : 0;
if(compare == 0){
compare = (primitive1 == primitive2) ? 0 : -1;
}
我认为第二个更好,应该更快,内存优化更多。但它们不是平等的吗?