Java

Java

Made by DeepSource

Primitives do not need to be boxed for comparison JAVA-W1050

Performance
Minor
Autofix

A boxed primitive is created just to call its compareTo method. It's more efficient to use the associated static compare method (for double and float since Java 1.4, for other primitive types since Java 7) which works on primitives directly.

Bad Practice

// This expression can be simplified to directly compare the primitive values instead.
Integer.valueOf(3).compareTo(2)

// or
new Integer(3).compareTo(2)

Recommended

Use the static compare() method of the corresponding type instead.

int compareResult = Integer.compare(3, 2);