How to find the minimum value in an ArrayList, along with the index number? (Java)

前端 未结 6 1697
醉话见心
醉话见心 2020-12-02 20:05

I need to get the index value of the minimum value in my arraylist in Java. MY arraylist holds several floats, and I\'m trying to think of a way I can get the index number o

6条回答
  •  情深已故
    2020-12-02 20:33

    There is an easier way to find a min integer in array list:

    int min = array.get(0);
            for (int i : array){
                min = min < i ? min : i;
            }
    

提交回复
热议问题