Java Array Min Value min(T... values)

Here you can find the source of min(T... values)

Description

min

License

Apache License

Declaration

@SafeVarargs
public static <T extends Comparable<? super T>> T min(T... values) 

Method Source Code

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

public class Main {

    @SafeVarargs
    public static <T extends Comparable<? super T>> T min(T... values) {
        T result = null;/*from www .j  ava 2s.  c  o m*/
        if (values != null) {
            for (T value : values) {
                if (compare(value, result, true) < 0) {
                    result = value;
                }
            }
        }
        return result;
    }

    public static <T extends Comparable<? super T>> int compare(T c1, T c2) {
        return compare(c1, c2, false);
    }

    public static <T extends Comparable<? super T>> int compare(T c1, T c2, boolean nullGreater) {
        if (c1 == c2) {
            return 0;
        } else if (c1 == null) {
            return nullGreater ? 1 : -1;
        } else if (c2 == null) {
            return nullGreater ? -1 : 1;
        }
        return c1.compareTo(c2);
    }
}

Related

  1. min(long[] array)
  2. min(long[] array)
  3. min(Number... array)
  4. min(Number[] array)
  5. min(T first, T... others)
  6. min(T[] args)
  7. min(T[] inputArray, int i, int i0)
  8. min_max_mean_stddev(long[] counts)
  9. min_of_ints(int[] data)