compareTo with primitives -> Integer / int
Is it better to write int primitive1 = 3, primitive2 = 4; Integer a = new Integer(primitive1); Integer b = new Integer(primitive2); int compare = a.compareTo(b); or int primitive1 = 3, primitive2 = 4; int compare = (primitive1 > primitive2) ? 1 : 0; if(compare == 0){ compare = (primitive1 == primitive2) ? 0 : -1; } I think the second one is better, should be faster and more memory optimized. But aren't they equal? Peter Lawrey For performance, it usually best to make the code as simple and clear as possible and this will often perform well (as the JIT will optimise this code best). In your