Java Utililty Methods Number Max Value

List of utility methods to do Number Max Value

Description

The list of methods to do Number Max Value are organized into topic(s).

Method

floatmax(final float a, final float b)
max
return a > b ? a : b;
floatmax(final float a, final float b, final float c)
Returns the maximum value of three floats.
return a > b ? a > c ? a : c : b > c ? b : c;
intmax(final int a, final int b)
Return the greater of the two values.
return (a >= b ? a : b);
intmax(final int a, final int b)
Provides an unbranched version of max for POSITIVE ints, it does 7 operation instead of branching (which is somewhat slower, but it's mainly here for educational purposes)
The original code can be found in: http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax
final int ab = a - b;
return b & (ab >> 31) | a & (~ab >> 31);
doublemax(final Iterable numbers)
max
double max = -Double.MAX_VALUE;
for (final Number number : numbers) {
    final double value = number.doubleValue();
    if (value > max) {
        max = value;
return max;
...
Doublemax(final Iterable values)
Retrieve the max element
Double max = Double.NEGATIVE_INFINITY;
for (final Double value : values) {
    if (max < value) {
        max = value;
return max;
NUMBER_TYPEmax(final NUMBER_TYPE n1, final NUMBER_TYPE n2)
max
if (n1 == null && n2 == null) {
    return null;
} else if (n1 == null) {
    return n2;
} else if (n2 == null) {
    return n1;
final int compared = compareTo(n1, n2);
...
NUMBER_TYPEmax(final NUMBER_TYPE number1, final NUMBER_TYPE number2)
max
if (number1 == null && number2 == null) {
    return null;
} else if (number1 == null) {
    return number2;
} else if (number2 == null) {
    return number1;
} else if (number1.doubleValue() > number2.doubleValue()) {
    return number1;
...
Stringmax(final String string1, final String string2)
Returns the shortest string.
if (string1 == null) {
    return string2;
} else if (string2 == null) {
    return string1;
return string1.length() > string2.length() ? string1 : string2;
floatmax(float a, float b)
max
return a > b ? a : b;