min value from Collection of Number - Java java.util

Java examples for java.util:Collection Algorithm

Description

min value from Collection of Number

Demo Code


//package com.java2s;
import java.util.Collection;

public class Main {
    public static void main(String[] argv) throws Exception {
        Collection list = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(min(list));
    }/*  w w w  . j a  v  a  2  s.c om*/

    public static Number min(Collection<Number> list) {
        Number min = list.iterator().next();
        for (Number item : list) {
            if (item.floatValue() < min.floatValue()) {
                min = item;
            }
        }
        return min;
    }
}

Related Tutorials