Java Array Max Value max(byte[] lArray, byte[] rArray)

Here you can find the source of max(byte[] lArray, byte[] rArray)

Description

max

License

Apache License

Declaration

final public static byte[] max(byte[] lArray, byte[] rArray) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    final public static byte[] max(byte[] lArray, byte[] rArray) {
        int cmp = compare(lArray, 0, lArray.length, rArray, 0, rArray.length);
        if (cmp >= 0) {
            return lArray;
        } else {//w ww.j ava  2s  . c  o  m
            return rArray;
        }
    }

    final public static int compare(byte[] lArray, int leftOffset, int lSize, byte[] rArray, int rightOffset,
            int rSize) {
        int i = leftOffset;
        int j = rightOffset;
        int n = lSize;
        for (int k = 0; k < n; k++, i++, j++) {
            if (k >= rSize) {
                return 1;
            }
            int cmp = (lArray[i] & 0xFF) - (rArray[j] & 0xFF);
            if (cmp != 0) {
                return cmp;
            }
        }
        if (lSize < rSize) {
            return -1;
        }
        return 0;
    }
}

Related

  1. findMaxValueIndex(double[] d)
  2. max(boolean useInt, int... value)
  3. max(byte[] arr)
  4. max(byte[] array)
  5. max(byte[] array)
  6. max(byte[] values)
  7. max(D... comparables)
  8. max(double array[], int start, int length)
  9. max(double values[])