获取list中的最大值,最小值

版权声明:转载说明出处,谢谢。 https://blog.csdn.net/Black_PL/article/details/80678548

方法一:

int max = List.get(0);
int min = List.get(0);
for (int i = 0; i < List.size(); i++){
   if(min > List.get(i)){
      min = List.get(i);
  }
   if(max > List.get(i)){
      max = List.get(i);
  }
}

方法二:待测试

int min = Collections.min(List);

int max = Collections.max(List);

猜你喜欢

转载自blog.csdn.net/Black_PL/article/details/80678548