Java Utililty Methods Array Max Value

List of utility methods to do Array Max Value

Description

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

Method

doublemaxDblArrayValue(int npts, double[] dbls)
Returns max value of an array of doubles.
if (npts == 0)
    return 0.0;
double max = dbls[0];
for (int i = 1; i < npts; i++)
    max = Math.max(max, dbls[i]);
return max;
intmaxdex(float... values)
Returns the index of the largest value in the given array.
int index = 0;
float max = values[0];
for (int i = 1; i < values.length; i++) {
    float value = values[i];
    if (value > max) {
        max = value;
        index = i;
return index;
intmaxdiffbits(int initoffset, int[] i, int pos, int length)
get the msb of differences among the consecutive input integers
int mask = 0;
mask |= (i[pos] - initoffset);
for (int k = pos + 1; k < pos + length; ++k) {
    mask |= i[k] - i[k - 1];
return bits(mask);
intmaxDiffLocation(double[] list1, double[] list2)
This method finds the largest difference between numbers in the same cell of the two lists and returns the location where that difference occurs.
int location = 0;
double val = (list1[location] - list2[location]);
for (int i = 0; i < list1.length; ++i) {
    if (Math.abs(list1[i] - list2[i]) > val) {
        location = i;
        val = Math.abs(list1[i] - list2[i]);
return location;
booleanmaxDistance(byte[] array, int maxDistance)
Returns true when the max distance between values in the array is NOT larger then the given value
if (array == null || array.length == 0) {
    return true;
int min = array[0];
int max = array[0];
for (byte value : array) {
    min = Math.min(value, min);
    max = Math.max(value, max);
...
doublemaxDouble(double a, double... others)
max Double
double rv = a;
for (double v : others) {
    rv = Math.max(rv, v);
return rv;
doublemaxElement(double[] d)
max Element
if (d.length == 0)
    throw new IllegalArgumentException("length cannot be 0.");
double maxValue = d[0];
for (int i = 1; i < d.length; i++) {
    if (d[i] > maxValue)
        maxValue = d[i];
return maxValue;
...
intmaxElement(int[] array)
max Element
int result = Integer.MIN_VALUE;
for (int element : array)
    result = Math.max(result, element);
return result;
intmaxElementIndex(final double[] array)
max Element Index
return maxElementIndex(array, array.length);
intmaxElementIndex(final double[] array)
max Element Index
return maxElementIndex(array, array.length);