September 2019
Intermediate to advanced
816 pages
18h 47m
English
Before JDK 8, a possible solution would be to rely on the Math.min() and Math.max() methods, as follows:
int i1 = -45;int i2 = -15;int min = Math.min(i1, i2);int max = Math.max(i1, i2);
The Math class provides a min() and a max() method for each primitive numeric type (int, long, float, and double).
Starting with JDK 8, each wrapper class of primitive numeric types (Integer, Long, Float, and Double) comes with dedicated min() and max() methods, and, behind these methods, there are invocations of their correspondents from the Math class. See the following example (this is a little bit more expressive):
double d1 = 0.023844D;double d2 = 0.35468856D;double min = Double.min(d1, d2);double max ...